asmysql
- PyPI: https://pypi.org/project/asmysql/
- GitHub: https://github.com/vastxiao/asmysql
- Gitee: https://gitee.com/vastxiao/asmysql
- Docs: https://vastxiao.github.io/asmysql/
Introduction
AsMysql - Python asyncio async MySQL client/connection pool, built on top of aiomysql. Supports async queries, reliable auto-commit, connection pool management, high performance, easy to use, production-ready.
Features
- Code supports type annotations.
- Very easy to use, simply inherit the AsMysql class for logical development.
- Supports automatic management of the MySQL connection pool and reconnection mechanism.
- Automatically captures and handles MysqlError errors globally.
- Separates MySQL connection engine and development logic class.
- Separates statement execution from data retrieval.
- Supports uncached data stream acquisition for large data result sets (without occupying memory).
- Reliable auto-commit: writes are persisted on success, failed statements are rolled back automatically (v2.3.0+).
Install
# Install from PyPI
pip install asmysql
AI-Assisted Development
asmysql ships an AI development skill (usage quickref + pitfall guide + doc map) and LLM-friendly docs entries for AI coding assistants (Claude Code / Cursor / Qoder / Codex, etc.).
One-command install (run at your project root; --target required, project-level preferred):
python -m asmysql skill install --target claude
--target |
Scope |
|---|---|
claude / cursor / agents |
Project-level (canonical .agents/skills/asmysql-dev/ + per-skill symlinks) |
user:claude / user:cursor / user:agents |
User-level (rooted at ~/) |
all / user:all |
Symlinks only into existing tool directories |
| Any path | Custom directory (comma-separated multi-targets supported) |
After upgrading asmysql, refresh with --force. Zero-install path: let your AI read the online SKILL.md and llms.txt directly.
- AI docs page: https://vastxiao.github.io/asmysql/v2/ai/
- llms.txt index: https://vastxiao.github.io/asmysql/ai/llms.txt
- Full docs (Chinese): https://vastxiao.github.io/asmysql/ai/llms-full.txt
Documentation
Quick Start v2
Using Engine class for MySQL connection:
import asyncio
from asmysql import Engine
# Create MySQL connection engine
engine = Engine(url="mysql://root:pass@127.0.0.1:3306/?charset=utf8mb4")
async def main():
# Connect to MySQL
await engine.connect()
# Execute SQL statement
async with engine.execute("select user,host from mysql.user") as result:
async for item in result.iterate():
print(item)
# Disconnect MySQL connection
await engine.disconnect()
asyncio.run(main())
Using AsMysql class for logical development:
import asyncio
from asmysql import Engine
from asmysql import AsMysql
# Write logical development class
class TestAsMysql(AsMysql):
async def print_users(self):
async with self.client.execute("select user,host from mysql.user") as result:
if result.error:
print(f"error_no: {result.error_no}, error_msg:{result.error_msg}")
else:
# result.iterate() is an asynchronous iterator that can fetch each row of the execution result.
async for item in result.iterate():
print(item)
async def main():
# Create MySQL connection engine
engine = Engine(host="192.168.1.192", port=3306)
# Connect to MySQL
await engine.connect()
# Create logical development class instance
test_mysql = TestAsMysql(engine)
# Execute logic
await test_mysql.print_users()
# Disconnect MySQL connection
await engine.disconnect()
asyncio.run(main())
Compatible with v1 version
import asyncio
from asmysql.v1 import AsMysql
# Directly inherit the AsMysql class for development:
class TestAsMysql(AsMysql):
# You can define some default parameters for the Mysql instance initialization here
# The attributes are consistent with the __init__ parameters
host = "127.0.0.1"
port = 3306
user = "root"
password = "pass"
async def get_users(self):
# The self.client attribute is specifically used to execute SQL statements, providing aiomysql's execute and execute_many methods.
result = await self.client.execute("select user,host from mysql.user")
# result is specifically used to obtain execution results, providing fetch_one, fetch_many, fetch_all, and iterate methods.
# result.err is the exception object (Exception) for all MySQL execution errors.
if result.err:
print(result.err_msg)
else:
# result.iterate() is an asynchronous iterator that can fetch each row of the execution result.
async for item in result.iterate():
print(item)
async def main():
# This will create an instance and connect to MySQL:
mysql = await TestAsMysql()
# Execute SQL statement
await mysql.get_users()
# Remember to disconnect the MySQL connection before exiting the program:
await mysql.disconnect()
asyncio.run(main())
Metadata
Release files for asmysql 2.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| asmysql-2.7.0.tar.gz | 31.3 kB | Without provenance | Details for asmysql-2.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asmysql-2.7.0-py3-none-any.whl | Python 3 | none | any | Details for asmysql-2.7.0-py3-none-any.whl |
Total release size: 70.3 kB
Release files / asmysql-2.7.0.tar.gz
| Download URL | asmysql-2.7.0.tar.gz |
|---|---|
| Size | 31.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
44a11ae02324ae9f5e15eee69afd9f3d627eb4d876372317fadd16556cf2cc5b
|
|
BLAKE2b-256 checksum How to use checksums |
452ea1f5140f27ba05c51f2110c96b83f888a1b50d16aec0e6c88b07877e02af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Kali GNU/Linux","version":"2026.1","id":"kali-rolling","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / asmysql-2.7.0-py3-none-any.whl
| Download URL | asmysql-2.7.0-py3-none-any.whl |
|---|---|
| Size | 38.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb16add5280daff7ce206c617ef4928234b265d619aafdd5d996df8b3ea35429
|
|
BLAKE2b-256 checksum How to use checksums |
0ab24a6b149be0c8ed25365d2a10931b7fc5e7db19695613f67a229713eda9a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Kali GNU/Linux","version":"2026.1","id":"kali-rolling","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for asmysql 2.7.0
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.