Skip to main content
Documentation Status

Trio-MySQL

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.

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 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

Documentation is available online: http://trio_mysql.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 trio_mysql.cursors

# Connect to the database
connection = trio_mysql.connect(host='localhost',
                             user='user',
                             password='passwd',
                             charset='utf8mb4',
                             database='db',
                             cursorclass=trio_mysql.cursors.DictCursor)

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, ('webmaster@python.org', 'very-secret'))

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

    # 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, ('webmistress@python.org', '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, ('webmaster@python.org',))
        result = await cursor.fetchone()
        print(result)

This example will print:

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

Resources

Trio chat: https://gitter.im/python-trio/general

License

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

Metadata

Release files for trio-mysql 1.0.3

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

Source distribution (sdist)

Source distribution for trio-mysql 1.0.3
File Size Uploaded
trio_mysql-1.0.3.tar.gz 47.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for trio-mysql 1.0.3
File Interpreter ABI Platform
trio_mysql-1.0.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 92.6 kB

Release files / trio_mysql-1.0.3.tar.gz

Download URL trio_mysql-1.0.3.tar.gz
Size 47.4 kB
Tags Source
SHA-256 checksum
How to use checksums
110de7b9ddc77cd9cfeaa08492d2b0dceafd393bc5ab2daec2be30114fea83e3
BLAKE2b-256 checksum
How to use checksums
ebeb3f5a8db4b9475c7f8b3ae0925689ec556065443374b6ac4c6e2c9ad71395
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / trio_mysql-1.0.3-py2.py3-none-any.whl

Download URL trio_mysql-1.0.3-py2.py3-none-any.whl
Size 45.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1a59acd39f439219ee87e0c23f507cecc18f7b282fca1f4253c34cef44d942ab
BLAKE2b-256 checksum
How to use checksums
c179c62d91546a81b8fab18278d57aac8533e415eecd30078f2b5da79a4e63bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

1 release file

0.10.1

1 release file

0.9.4

2 release files

0.9.3

1 release file

0.8.0

1 release file

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