Skip to main content

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

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.

Metadata

Release files for mysql-context-manager 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mysql-context-manager 0.3.0
File Size Uploaded Provenance Actions
mysql_context_manager-0.3.0.tar.gz 3.9 kB Without provenance Details for mysql_context_manager-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mysql-context-manager 0.3.0
File Interpreter ABI Platform Actions
mysql_context_manager-0.3.0-py3-none-any.whl Python 3 none any Details for mysql_context_manager-0.3.0-py3-none-any.whl

Total release size: 8.2 kB

Release files / mysql_context_manager-0.3.0.tar.gz

Download URL mysql_context_manager-0.3.0.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c99c10f0814fdf268f1d0f82854f7ce68461205680a854553ede3ea993ac2294
BLAKE2b-256 checksum
How to use checksums
4f03ff076d902d135cf677740330c9d78c640a60cbd307e37067074a4f6218eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.12.8 Linux/6.8.0-1017-azure

Release files / mysql_context_manager-0.3.0-py3-none-any.whl

Download URL mysql_context_manager-0.3.0-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00ecb5110affdbdcbaa766ae4e39be74fe90493500e9a67a2ba27c40bfe425a9
BLAKE2b-256 checksum
How to use checksums
197d5262c4e4ab627febb3e69cec12091580625ab591e942533e40ab5d5bb716
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.12.8 Linux/6.8.0-1017-azure

Security for mysql-context-manager 0.3.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page