An Asynchronous MySQL Client Engine Using Aiomysql.
Project description
asmysql
- PyPI: https://pypi.org/project/asmysql/
- GitHub: https://github.com/vastxiao/asmysql
- Gitee: https://gitee.com/vastxiao/asmysql
Introduction
asmysql is a library for using the MySQL asynchronous client, which is a wrapper for aiomysql.
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 statement execution from data retrieval.
Install
# Install from PyPI
pip install asmysql
Documentation
Quick Start
import asyncio
from asmysql 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,authentication_string,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()
await mysql.get_users()
# Remember to disconnect the MySQL connection before exiting the program:
await mysql.disconnect()
asyncio.run(main())
Support for asynchronous context managers.
import asyncio
from asmysql import AsMysql
class TestAsMysql(AsMysql):
async def get_users(self):
result = await self.client.execute('select user,authentication_string,host from mysql.user')
if result.err:
print(result.err)
else:
async for item in result.iterate():
print(item)
async def main():
# Using async with will automatically close the MySQL connection when the code exits.
async with TestAsMysql() as mysql:
await mysql.get_users()
if __name__ == '__main__':
asyncio.run(main())
More Usage
import asyncio
from asmysql import AsMysql
class TestAsMysql(AsMysql):
async def get_users(self):
result = await self.client.execute('select user,authentication_string,host from mysql.user')
if result.err:
print(result.err)
else:
return await result.fetch_all()
# When creating a MySQL instance, parameters such as MySQL address and user password can be passed in.
mysql = TestAsMysql(host='192.168.1.192', port=3306)
async def main():
# This will connect to MySQL:
await mysql.connect() # or: await mysql
print(await mysql.get_users())
# Disconnect MySQL connection:
await mysql.disconnect()
asyncio.run(main())
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 asmysql-1.2.0.tar.gz.
File metadata
- Download URL: asmysql-1.2.0.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fde869a870090847484c41d3707444b2b1fe5db508c8f72f7e6bf8f772354b3c
|
|
| MD5 |
a86ce9004ddcf5a49864a54adaf47795
|
|
| BLAKE2b-256 |
617a17fb3eca1ec876b288ed9c52b9d1fc9fc65a8ea8101ae800764ac660516e
|
Provenance
The following attestation bundles were made for asmysql-1.2.0.tar.gz:
Publisher:
python_package_publish_to_pypi.yml on Vastxiao/asmysql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
asmysql-1.2.0.tar.gz -
Subject digest:
fde869a870090847484c41d3707444b2b1fe5db508c8f72f7e6bf8f772354b3c - Sigstore transparency entry: 244527331
- Sigstore integration time:
-
Permalink:
Vastxiao/asmysql@010247d6b1b09a0958ae4f075e63a7dcbb410ed0 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/Vastxiao
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python_package_publish_to_pypi.yml@010247d6b1b09a0958ae4f075e63a7dcbb410ed0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file asmysql-1.2.0-py3-none-any.whl.
File metadata
- Download URL: asmysql-1.2.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6093ffe49b3ddd229d5636c9a419fb5f214aa68145de79152c1bbb168128fffa
|
|
| MD5 |
92c0b380c68bc5c37852f35ddb431af6
|
|
| BLAKE2b-256 |
f84da7a4469cbf543b9b9d3025d35486dcd9ce4cd0de5f9c3cff3ff127813644
|
Provenance
The following attestation bundles were made for asmysql-1.2.0-py3-none-any.whl:
Publisher:
python_package_publish_to_pypi.yml on Vastxiao/asmysql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
asmysql-1.2.0-py3-none-any.whl -
Subject digest:
6093ffe49b3ddd229d5636c9a419fb5f214aa68145de79152c1bbb168128fffa - Sigstore transparency entry: 244527334
- Sigstore integration time:
-
Permalink:
Vastxiao/asmysql@010247d6b1b09a0958ae4f075e63a7dcbb410ed0 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/Vastxiao
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python_package_publish_to_pypi.yml@010247d6b1b09a0958ae4f075e63a7dcbb410ed0 -
Trigger Event:
release
-
Statement type: