Skip to main content
Documentation Status https://coveralls.io/repos/PyMySQL/PyMySQL/badge.svg?branch=master&service=github https://img.shields.io/lgtm/grade/python/g/PyMySQL/PyMySQL.svg?logo=lgtm&logoWidth=18

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

  • Python – one of the following:

  • MySQL Server – one of the following:

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

License

PyMySQL is released under the MIT License. See LICENSE for more information.

Metadata

Release files for PyMySQL 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyMySQL 1.0.1
File Size Uploaded Provenance Actions
PyMySQL-1.0.1.tar.gz 45.4 kB Without provenance Details for PyMySQL-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for PyMySQL 1.0.1
File Interpreter ABI Platform Actions
PyMySQL-1.0.1-py3-none-any.whl Python 3 none any Details for PyMySQL-1.0.1-py3-none-any.whl

Total release size: 89.2 kB

Release files / PyMySQL-1.0.1.tar.gz

Download URL PyMySQL-1.0.1.tar.gz
Size 45.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b46be62180008086fa9365a91c39a8853066ea5e8cde3a1e24491fb7de4b9286
BLAKE2b-256 checksum
How to use checksums
68203fcd05d84a64c1052e62962a59815c11b201ffca56afb73b8c4c6b341545
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / PyMySQL-1.0.1-py3-none-any.whl

Download URL PyMySQL-1.0.1-py3-none-any.whl
Size 43.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e651185cc1785c7c9e81a88329664b16c23f2f3d073b9ea6816406b351296ac8
BLAKE2b-256 checksum
How to use checksums
36820ca3353cf54dcf17a6bd239c533fff8d4c19153b8719af2397a302c66a5a
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for PyMySQL 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

0.6.5

0.6.2-rc1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page