Pure Python MySQL Driver
Project description
PyMySQL
This package contains a pure-Python MySQL client library, based on PEP 249.
Most public APIs are compatible with mysqlclient and MySQLdb.
NOTE: PyMySQL doesn’t support low level APIs _mysql provides like data_seek, store_result, and use_result. You should use high level APIs defined in PEP 249. But some APIs like autocommit and ping are supported because PEP 249 doesn’t cover their usecase.
Requirements
Installation
Package is uploaded on PyPI.
You can install it with pip:
$ python3 -m pip install PyMySQL
To use “sha256_password” or “caching_sha2_password” for authenticate, you need to install additional dependency:
$ python3 -m pip install PyMySQL[rsa]
To use MariaDB’s “ed25519” authentication method, you need to install additional dependency:
$ python3 -m pip install PyMySQL[ed25519]
Documentation
Documentation is available online: https://pymysql.readthedocs.io/
For support, please refer to the StackOverflow.
Example
The following examples make use of a simple table
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(255) COLLATE utf8_bin NOT NULL,
`password` varchar(255) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
AUTO_INCREMENT=1 ;
import pymysql.cursors
# Connect to the database
connection = pymysql.connect(host='localhost',
user='user',
password='passwd',
database='db',
cursorclass=pymysql.cursors.DictCursor)
with connection:
with connection.cursor() as cursor:
# Create a new record
sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
cursor.execute(sql, ('webmaster@python.org', 'very-secret'))
# connection is not autocommit by default. So you must commit to save
# your changes.
connection.commit()
with connection.cursor() as cursor:
# Read a single record
sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
cursor.execute(sql, ('webmaster@python.org',))
result = cursor.fetchone()
print(result)
This example will print:
{'password': 'very-secret', 'id': 1}
Resources
DB-API 2.0: https://www.python.org/dev/peps/pep-0249/
MySQL Reference Manuals: https://dev.mysql.com/doc/
MySQL client/server protocol: https://dev.mysql.com/doc/internals/en/client-server-protocol.html
“Connector” channel in MySQL Community Slack: https://lefred.be/mysql-community-on-slack/
PyMySQL mailing list: https://groups.google.com/forum/#!forum/pymysql-users
License
PyMySQL is released under the MIT License. See LICENSE for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file PyMySQL-1.0.2.tar.gz
.
File metadata
- Download URL: PyMySQL-1.0.2.tar.gz
- Upload date:
- Size: 45.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.1.0.post20201221 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 816927a350f38d56072aeca5dfb10221fe1dc653745853d30a216637f5d7ad36 |
|
MD5 | 3fe6ff2eefb58af5c54d335c6e0216de |
|
BLAKE2b-256 | 60ea33b8430115d9b617b713959b21dfd5db1df77425e38efea08d121e83b712 |
File details
Details for the file PyMySQL-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: PyMySQL-1.0.2-py3-none-any.whl
- Upload date:
- Size: 43.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.1.0.post20201221 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41fc3a0c5013d5f039639442321185532e3e2c8924687abe6537de157d403641 |
|
MD5 | 9ae4fbf26a0d3752dc78cf8444d1bf0d |
|
BLAKE2b-256 | 4f52a115fe175028b058df353c5a3d5290b71514a83f67078a6482cff24d6137 |