Skip to main content

pymysqlhelper

A unified SQLAlchemy wrapper for SQLite and MySQL.


Overview

pymysqlhelper provides two classes:

  • LocalDatabase (SQLite)
  • Database (MySQL)

Both expose an identical API, allowing you to:

  • Develop locally using SQLite
  • Switch to MySQL in production
  • Change only the constructor — no other code modifications needed

All functionality is shared through a common _DatabaseMixin, ensuring consistency across both backends.


Installation

pip install pymysqlhelper

All dependencies are installed automatically (sqlalchemy, pymysql)


Quick Start

SQLite (Local Development)

from pymysqlhelper import LocalDatabase, Integer, String, Text

db = LocalDatabase("myapp.db")

db.define_table(
    "users",
    id=Integer,
    name=String(100),
    email=Text,
)

db.insert("users", id=1, name="Alice", email="alice@example.com")
db.insert("users", id=1, name="Alice Updated", email="alice@example.com").replace()
db.insert("users", id=1, name="Alice", email="alice@example.com").ignore()

user = db.get("users", id=1)
print(user)

MySQL (Production)

from pymysqlhelper import Database

db = Database("root", "secret", "localhost", 3306, "myapp")

db.define_table("users", id=Integer, name=String(100), email=Text)
db.insert("users", id=1, name="Alice", email="alice@example.com")

Connecting

SQLite

LocalDatabase("local.db")     # File-based
LocalDatabase(":memory:")     # In-memory (testing)

MySQL

Database(
    username="user",
    password="password",
    host="localhost",
    port=3306,
    database="myapp",
)

Defining Tables

from sqlalchemy import Integer, String, Text, Float, ForeignKey

db.define_table(
    "orders",
    id=Integer,
    user_id=(Integer, ForeignKey("users.id")),
    total=Float(),
    note=Text,
)
  • First column is always the primary key (autoincrement=False)
  • Safe to call multiple times (no-op if table exists)

Supported Types

  • Integer, BigInteger, SmallInteger
  • Boolean
  • Float, DECIMAL
  • String(n), Text
  • DateTime, Date, Time
  • LargeBinary

Inserting Data

db.insert("users", id=1, name="Alice")
db.insert("users", id=1, name="Alice").ignore()
db.insert("users", id=1, name="Bob").replace()

Bulk Insert

db.bulk_insert("users", [
    {"id": 2, "name": "Bob"},
    {"id": 3, "name": "Carol"},
])

Querying Data

Multiple Rows

db.search("users")
db.search("users", name="Alice")

Single Row

db.get("users", id=1)

Pagination

db.search_paginated("users", page=2, page_size=20)

Other Helpers

db.count_rows("users")
db.distinct_values("users", "role")

Updating & Deleting

db.update("users", filters={"id": 1}, updates={"name": "Alicia"})
db.delete("users", id=1)

Schema Inspection

db.list_tables()
db.list_columns("users")
db.get_table_schema("users")
db.get_column_type("users", "name")

Schema Modifications

db.add_column("users", "age", Integer)
db.drop_column("users", "bio")
db.edit_column_type("users", "age", Integer)
db.rename_table("users", "accounts")
db.delete_table("temp")

Reload Schema

db.reload()

Use this if schema changes outside the library.

Metadata

Release files for pymysqlhelper 1.12.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 pymysqlhelper 1.12.0
File Size Uploaded Provenance Actions
pymysqlhelper-1.12.0.tar.gz 15.5 kB Without provenance Details for pymysqlhelper-1.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pymysqlhelper 1.12.0
File Interpreter ABI Platform Actions
pymysqlhelper-1.12.0-py3-none-any.whl Python 3 none any Details for pymysqlhelper-1.12.0-py3-none-any.whl

Total release size: 33.9 kB

Release files / pymysqlhelper-1.12.0.tar.gz

Download URL pymysqlhelper-1.12.0.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
693fa04e887cd24b801620413e3054e986961bfd012647abebeb6d4f6730d6c2
BLAKE2b-256 checksum
How to use checksums
5e0986030d0a5669743c3e950c8836a35dc72e16aea7b1a38649e88d199d2b25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / pymysqlhelper-1.12.0-py3-none-any.whl

Download URL pymysqlhelper-1.12.0-py3-none-any.whl
Size 18.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
179866d2371065d21818d743fa3e6476fe5b4e53ceb63c8c64f3a95f15fb64ac
BLAKE2b-256 checksum
How to use checksums
a46bd0ca6b8a2881f23faf6c75de3aef803c93a58f4ae4d527a2e07ef0cdd164
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for pymysqlhelper 1.12.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