DM-aiomysql
Urls
* Package contains both asynchronous and synchronous clients
Usage
Run in Windows
If you run async code in Windows, set correct selector
import asyncio
import sys
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
Example of using DMAioMysqlClient
Analogue to DMAioMysqlClient is the synchronous client DMMysqlClient.
from dm_aiomysql import DMAioMysqlClient
import asyncio
async def main():
# create client
mysql_client = DMAioMysqlClient("localhost", 3306, "username", "password", "database")
# execute query - results is list[list[Any]]
list_results = await mysql_client.query("SELECT * FROM users")
# execute query - results is list[dict[str, Any]
dict_results = await mysql_client.query("SELECT * FROM users", dict_results=True)
# execute query with params placeholders
results = await mysql_client.query("SELECT * FROM users WHEN name = %s", params=["John"])
# commit data
await mysql_client.query("UPDATE users SET age = %s WHERE id = %s", params=[25, 2], commit=True)
# insert data
data = {"id": 1, "name": "John_1", "age": 21}
await mysql_client.insert_one("my_table", data)
# insert many data
data_list = [{"id": 2, "name": "John_2", "age": 22}, {"id": 3, "name": "John_3", "age": 23}]
await mysql_client.insert_many("users", data_list)
if __name__ == "__main__":
asyncio.run(main())
Example of using DMAioEnvMysqlClient
DMAioEnvMysqlClient fully inherits the DMAioMysqlClient class.
But the connection parameters are loaded from the ENV variables.
The client will not be created until all ENV variables are set.
Analogue to DMAioEnvMysqlClient is the synchronous client DMEnvMysqlClient.
from dm_aiomysql import DMAioEnvMysqlClient
from dotenv import load_dotenv, find_dotenv
# load ENV variables
load_dotenv(find_dotenv())
# create default client
mysql_client = DMAioEnvMysqlClient()
# needed ENV variables MYSQL_HOST, MYSQL_PORT, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_DATABASE
# create custom client
custom_mysql_client = DMAioEnvMysqlClient(env_prefix="PROD_MYSQL") # by default: env_prefix="MYSQL"
# needed ENV variables PROD_MYSQL_HOST, PROD_MYSQL_PORT, ...
Set custom logger
from dm_aiomysql import DMEnvMysqlClient
from dm_logger import FormatterConfig
# set up custom logger for all clients
DMEnvMysqlClient.set_logger_params(
{
"name": "my_name",
"formatter_config": FormatterConfig(
show_datetime=False,
)
}
)
See more about DMLogger here
Release files for dm-aiomysql 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dm_aiomysql-0.1.5.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dm_aiomysql-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / dm_aiomysql-0.1.5.tar.gz
| Download URL | dm_aiomysql-0.1.5.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7bd7a1f2d40cbe20df1b2dc91d2cbf76e6647bade18f2efcc303a814e53244e9
|
|
BLAKE2b-256 checksum How to use checksums |
ea8309f759ba82c785572620da6c24d1ae4a39b2dc6943fd1c06b8c4568cf2b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / dm_aiomysql-0.1.5-py3-none-any.whl
| Download URL | dm_aiomysql-0.1.5-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69a1f13609a588351b6cd1fdefbc7fa5feed36cdb59f2f7f3ef7dd43a8e35850
|
|
BLAKE2b-256 checksum How to use checksums |
81976432b71cbe38de89ec4ccd4e0ceab2812fd0589553bbdbee1e9ef838a1ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|