A pure-Python MySQL and MariaDB client library implementing the Python DB-API 2.0 specification.
PyMySQL is a pure-Python client library for connecting to MySQL and MariaDB databases from Python applications. It implements the Python DB-API 2.0 specification (PEP 249), providing a standardized interface for executing SQL queries, managing transactions, and handling database connections. The library enables Python developers to interact with MySQL-compatible databases without requiring external C dependencies.
Python developers who need to connect their applications to MySQL or MariaDB databases, particularly those who prefer pure-Python solutions or work in environments where C extensions are problematic.
PyMySQL offers a clean, dependency-free Python implementation that's easy to install and deploy across different platforms while maintaining full compatibility with MySQL and MariaDB features. Unlike some alternatives, it has no external C dependencies, making it more portable and simpler to manage in various deployment scenarios.
MySQL client library for Python
No external C dependencies make installation straightforward with 'pip install PyMySQL', ensuring cross-platform compatibility without compilation issues, as highlighted in the README's installation section.
Implements DB-API 2.0 (PEP 249), providing a consistent interface familiar to Python developers, which reduces learning curve and ensures interoperability with other database tools.
Compatible with both MySQL LTS versions and MariaDB LTS versions, offering flexibility in database choice without needing separate libraries, as specified in the requirements.
Supports sha256_password, caching_sha2_password, and MariaDB's ed25519 methods with optional dependencies, keeping up with security advancements in MySQL/MariaDB ecosystems.
Includes DictCursor for returning rows as dictionaries, making data access more intuitive for Python workflows, as demonstrated in the example code snippet.
For modern authentication methods like sha256_password or ed25519, additional packages (PyMySQL[rsa] or PyMySQL[ed25519]) must be installed, adding setup steps and potential dependency conflicts.
As a pure-Python implementation, it may not match the speed of C-based alternatives like mysqlclient in high-throughput scenarios, which could impact data-intensive applications.
Some Python frameworks and ORMs, such as Django, default to or are optimized for other drivers, requiring extra configuration and potentially lacking seamless integration out-of-the-box.
Lacks built-in connection pooling or some database-specific optimizations found in more mature drivers, necessitating manual implementation or third-party solutions for scalability.
pymysql is an open-source alternative to the following products:
Go MySQL Driver is a MySQL driver for Go's (golang) database/sql package
Redis Python client
A curated list of awesome PostgreSQL software, libraries, tools and resources, inspired by awesome-mysql
PyMongo - the Official MongoDB Python driver
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.