Registry / type-stubs / types-pymysql

types-pymysql

JSON →
library1.2.0.20260807pypypi✓ verified 26d ago

This package provides static type annotations (stubs) for the PyMySQL library, enabling type checkers like Mypy or Pyright to analyze code that uses PyMySQL. It helps catch type-related errors before runtime and improves IDE autocomplete and refactoring. The current version is 1.1.0.20260408, with updates often aligned with new `pymysql` releases or as needed by the typeshed project.

pip install types-pymysql
INSTALL
IMPORT
SIG · TYPES-PYMYSQL
T
types-pymysql
type-stubspythonv1.2.0.20260807
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.0.20260807 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pymysql-stubs
import pymysql-stubs
import pymysql-stubs

This quickstart demonstrates how to use PyMySQL with type hints. Installing `types-pymysql` allows your type checker to understand the types returned by `pymysql.connect`, `conn.cursor()`, and methods like `cursor.execute()` and `cursor.fetchall()`, improving code quality and maintainability. Remember that `types-pymysql` provides *stubs*; you still need to `pip install pymysql` to run this code at runtime.

import pymysql from pymysql.cursors import DictCursor import os # These environment variables simulate configuration for a MySQL database. # Replace with your actual database details or set environment variables. DB_HOST = os.environ.get('MYSQL_HOST', 'localhost') DB_USER = os.environ.get('MYSQL_USER', 'root') DB_PASSWORD = os.environ.get('MYSQL_PASSWORD', 'password') DB_NAME = os.environ.get('MYSQL_DB', 'test_db') def get_example_data() -> list[dict]: """Connects to a MySQL database and fetches some example data.""" try: # types-pymysql provides type hints for pymysql.connect's return (Connection) with pymysql.connect( host=DB_HOST, user=DB_USER, password=DB_PASSWORD, database=DB_NAME, cursorclass=DictCursor # Type stubs help with DictCursor return types ) as conn: # 'conn' is typed as 'pymysql.connections.Connection' with conn.cursor() as cursor: # 'cursor' is typed as 'pymysql.cursors.DictCursor' # Type stubs ensure 'execute' and 'fetchall' method signatures are known cursor.execute("SELECT 1 as id, 'hello' as message") result: list[dict] = cursor.fetchall() return result except pymysql.Error as e: print(f"Database connection or query error: {e}") return [] if __name__ == "__main__": # This code requires 'pymysql' to be installed and a running MySQL server. # 'types-pymysql' enhances static analysis of this code. data = get_example_data() if data: print("Fetched data:", data) else: print("Failed to fetch data. Check database connection and `pymysql` installation.")
Debug
Known issues
gotchaInstalling `types-pymysql` provides *only* type annotations (stubs); it does not install the `pymysql` library itself. You must `pip install pymysql` separately for your application to function at runtime.
fix
Ensure both `pymysql` and `types-pymysql` are installed (`pip install pymysql types-pymysql`).
affects: All
gotchaType stubs are consumed by static type checkers (e.g., Mypy, Pyright). If your type checker isn't finding the stubs, ensure it's properly configured to discover installed type packages. Some environments might require explicit configuration for stub discovery.
fix
Consult your type checker's documentation (e.g., `mypy --install-types` or configuring `pyproject.toml`) to ensure it correctly finds `types-pymysql`.
affects: All
gotchaType stubs in typeshed might occasionally lag behind the absolute latest features or minor versions of `pymysql`. While efforts are made to keep them up-to-date, new `pymysql` releases might introduce changes not immediately reflected in the stubs, leading to `Any` types or type-checking errors for very new features.
fix
If encountering issues with new `pymysql` features, check the `typeshed` GitHub repository for updates or open an issue. Consider pinning `pymysql` to a version known to be well-supported by the current stubs.
affects: All
Upgrade
Version history
1.2.0.20260807latest on PyPI · released Aug 7, 2026
Audit
Dependencies
pymysqloptionalThe runtime library for which these stubs provide type hints.
Agent activity
42 hits · last 30 days
node
38
Meta
1
OpenAI (training)
1
Resources
types-pymysql — pip install types-pymysql · libregistry