Skip to main content

Work with MySQL databases asynchronously, and in context.

Project description

MySQL Context Manager

Work with MySQL based databases asynchronously, using a context manager.

PyPI version PyPI downloads Build status Code coverage Codacy Badge Support Python versions Code style: Black

Getting started

You can get mysql-context-manager from PyPI, which means you can install it with pip easily:

python -m pip install mysql-context-manager

Example

from mysql_context_manager import MysqlConnector

async with MysqlConnector(hostname="localhost") as conn:
    results = await conn.query("select username from users where is_bender = 1 order by username asc;")
assert results[0]["username"] == "Aang"
assert results[1]["username"] == "Katara"
assert results[2]["username"] == "Toph"

Example using SQLAlchemy

from mysql_context_manager import MysqlConnector
import sqlalchemy
from sqlalchemy.dialects import mysql

metadata = sqlalchemy.MetaData()

users = sqlalchemy.Table(
    "users",
    metadata,
    sqlalchemy.Column("user_id", mysql.INTEGER(), autoincrement=True, nullable=False),
    sqlalchemy.Column("username", mysql.VARCHAR(length=128), nullable=False),
    sqlalchemy.Column("is_bender", mysql.SMALLINT(), autoincrement=False, nullable=True),
    sqlalchemy.PrimaryKeyConstraint("user_id"),
    mysql_default_charset="utf8mb4",
    mysql_engine="InnoDB",
)

async with MysqlConnector(hostname="localhost") as conn:
    results = await conn.query(users.select().where(users.c.username == "Aang"))
assert results[0]["username"] == "Aang"
assert results[0]["is_bender"] == 1

Changelog

Refer to the CHANGELOG.rst file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mysql_context_manager-0.2.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

mysql_context_manager-0.2.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file mysql_context_manager-0.2.0.tar.gz.

File metadata

  • Download URL: mysql_context_manager-0.2.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.3 Linux/5.15.0-1037-azure

File hashes

Hashes for mysql_context_manager-0.2.0.tar.gz
Algorithm Hash digest
SHA256 450ff68dbf8480dca78a6612c54abdc1cfe93b4164294052000cb9ff37e91b91
MD5 1f2c181904c1bd24496547a0d6cc5a0f
BLAKE2b-256 3bf627934cbc5b2169ae5c1487dc6e50a4e6c3aaeac3c9d642bb74be3d1fb1bc

See more details on using hashes here.

File details

Details for the file mysql_context_manager-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mysql_context_manager-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2eae1897b8f84c7262fbb289180f26588ddef2fb66ac9655e726008aceafdf4b
MD5 c6736e3c02e8d1fef69c1cb47b40426a
BLAKE2b-256 c2daf6eb64b3f3d76deeb7eabd367608abcdac607f300f20e3699b3e5c9083d9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page