Skip to main content

Pure Python MySQL Driver

Project description

Documentation Status


This package contains a pure-Python and Trio-enhanced MySQL client library. It is a mostly-straightforward clone of PyMySQL, adding async methods compatible with the Trio framework.

NOTE: Trio-MySQL tries to adhere to (an async version of) the high level database APIs defined in PEP 249. Some differences, however, are unavoidable.


  • Python – one of the following:
  • MySQL Server – one of the following:


Package is uploaded on PyPI.

You can install it with pip:

$ python3 -m pip install trio_mysql

To use “sha256_password” or “caching_sha2_password” for authenticate, you need to install additional dependency:

$ python3 -m pip install trio_mysql[rsa]

To use MariaDB’s “ed25519” authentication method, you need to install additional dependency:

$ python3 -m pip install PyMySQL[ed25519]


Documentation is available online:

For support, please refer to the StackOverflow.


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`)
import trio_mysql.cursors

# Connect to the database
connection = trio_mysql.connect(host='localhost',

async with connection as conn:
    async with conn.cursor() as cursor:
        # Create a new record
        sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
        await cursor.execute(sql, ('', 'very-secret'))

    # connection is not autocommit by default. So you must commit to save
    # your changes.

    # You can set up a transaction:
    async with conn.transaction():
        async with conn.cursor() as cursor:
            # Create a new record
            sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
            await cursor.execute(sql, ('', 'totally-secret'))

    # ... or use a cursor directly, for autocommit:
    async with conn.cursor() as cursor:
        # Read a single record
        sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
        await cursor.execute(sql, ('',))
        result = await cursor.fetchone()

This example will print:

{'password': 'very-secret', 'id': 1}


Trio-MySQL is released under the MIT License. See LICENSE for more information.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for trio-mysql, version 1.0.3
Filename, size File type Python version Upload date Hashes
Filename, size trio_mysql-1.0.3.tar.gz (47.4 kB) File type Source Python version None Upload date Hashes View
Filename, size trio_mysql-1.0.3-py2.py3-none-any.whl (45.3 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page