MySQL driver for asyncio.
Project description
aiomysql is a “driver” for accessing a MySQL database from the asyncio (PEP-3156/tulip) framework. It depends on and reuses most parts of PyMySQL . aiomysql tries to be like awesome aiopg library and preserve same api, look and feel.
Internally aiomysql is copy of PyMySQL, underlying io calls switched to async, basically yield from and asyncio.coroutine added in proper places)). sqlalchemy support ported from aiopg.
Documentation
Basic Example
aiomysql based on PyMySQL , and provides same api, you just need to use await conn.f() or yield from conn.f() instead of calling conn.f() for every method.
Properties are unchanged, so conn.prop is correct as well as conn.prop = val.
import asyncio
import aiomysql
async def test_example():
async with aiomysql.create_pool(host='127.0.0.1', port=3306,
user='root', password='',
db='mysql') as pool:
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 42;")
print(cur.description)
(r,) = await cur.fetchone()
assert r == 42
asyncio.run(test_example())
Example of SQLAlchemy optional integration
Sqlalchemy support has been ported from aiopg so api should be very familiar for aiopg user.:
import asyncio
import sqlalchemy as sa
from aiomysql.sa import create_engine
metadata = sa.MetaData()
tbl = sa.Table('tbl', metadata,
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('val', sa.String(255)))
async def go():
engine = await create_engine(user='root', db='test_pymysql',
host='127.0.0.1', password='')
async with engine.acquire() as conn:
await conn.execute(tbl.insert().values(val='abc'))
await conn.execute(tbl.insert().values(val='xyz'))
async for row in conn.execute(tbl.select()):
print(row.id, row.val)
engine.close()
await engine.wait_closed()
asyncio.run(go())
Requirements
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiomysql-0.3.2.tar.gz.
File metadata
- Download URL: aiomysql-0.3.2.tar.gz
- Upload date:
- Size: 108.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72d15ef5cfc34c03468eb41e1b90adb9fd9347b0b589114bd23ead569a02ac1a
|
|
| MD5 |
b231ff658904964e25912f0e033f94e8
|
|
| BLAKE2b-256 |
29e0302aeffe8d90853556f47f3106b89c16cc2ec2a4d269bdfd82e3f4ae12cc
|
Provenance
The following attestation bundles were made for aiomysql-0.3.2.tar.gz:
Publisher:
ci-cd.yml on aio-libs/aiomysql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiomysql-0.3.2.tar.gz -
Subject digest:
72d15ef5cfc34c03468eb41e1b90adb9fd9347b0b589114bd23ead569a02ac1a - Sigstore transparency entry: 628984482
- Sigstore integration time:
-
Permalink:
aio-libs/aiomysql@72a4df674ae5466028f2b762917f938813bb147d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/aio-libs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci-cd.yml@72a4df674ae5466028f2b762917f938813bb147d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file aiomysql-0.3.2-py3-none-any.whl.
File metadata
- Download URL: aiomysql-0.3.2-py3-none-any.whl
- Upload date:
- Size: 71.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c82c5ba04137d7afd5c693a258bea8ead2aad77101668044143a991e04632eb2
|
|
| MD5 |
1eb90e1db93899b15aaacf8f14573765
|
|
| BLAKE2b-256 |
4cafaae0153c3e28712adaf462328f6c7a3c196a1c1c27b491de4377dd3e6b52
|
Provenance
The following attestation bundles were made for aiomysql-0.3.2-py3-none-any.whl:
Publisher:
ci-cd.yml on aio-libs/aiomysql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiomysql-0.3.2-py3-none-any.whl -
Subject digest:
c82c5ba04137d7afd5c693a258bea8ead2aad77101668044143a991e04632eb2 - Sigstore transparency entry: 628984485
- Sigstore integration time:
-
Permalink:
aio-libs/aiomysql@72a4df674ae5466028f2b762917f938813bb147d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/aio-libs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci-cd.yml@72a4df674ae5466028f2b762917f938813bb147d -
Trigger Event:
workflow_dispatch
-
Statement type: