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

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.3.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mysql_context_manager-0.3.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mysql_context_manager-0.3.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.8.0-1017-azure

File hashes

Hashes for mysql_context_manager-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c99c10f0814fdf268f1d0f82854f7ce68461205680a854553ede3ea993ac2294
MD5 c10c6b0d5957e905a5dccd5bff8e4302
BLAKE2b-256 4f03ff076d902d135cf677740330c9d78c640a60cbd307e37067074a4f6218eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mysql_context_manager-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00ecb5110affdbdcbaa766ae4e39be74fe90493500e9a67a2ba27c40bfe425a9
MD5 9014d595ef307af2baa155103e098df6
BLAKE2b-256 197d5262c4e4ab627febb3e69cec12091580625ab591e942533e40ab5d5bb716

See more details on using hashes here.

Supported by

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