Skip to main content

A lightweight, type-hinted wrapper around Python's DB-API 2.0.

Project description

typeddbapi

A lightweight, type-hinted wrapper around Python's DB-API 2.0.

What is typeddbapi?

typeddbapi provides a simple way to connect to databases using URL strings, with full type hints and optional connection pooling. You write raw SQL for your specific database—typeddbapi just passes it through to your driver.

Why typeddbapi?

  • Raw SQL First - No ORM magic, no query translation. You write the SQL you want to execute.
  • Type-Hinted Throughout - Full type annotations for better IDE support and runtime type checking.
  • Driver Agnostic - Works with any DB-API 2.0 compatible driver (psycopg, sqlite3, mysql-connector, asyncpg, aiosqlite, and more).
  • Optional Pooling - Connection pool utilities available when you need them.
  • Async Support - Both synchronous and asynchronous APIs with the same intuitive interface.

[!WARNING] Async support is only for asynchronous drivers (e.g. aiosqlite)

What typeddbapi is NOT

  • Not a cross-database compatibility layer
  • Not an ORM
  • Not a query builder
  • Not a SQL validator or translator

typeddbapi Philosophy

typeddbapi directly gives your raw SQL query to the database driver specified in the URL rather than trying to abstract it away. If someone wants an ORM, they can build one on top.

Connection URLs

typeddbapi uses standard RFC-1738 URLs with dialect and optional driver:

dialect[+driver]://user:pass@host:port/database

Examples:

  • postgresql://localhost/mydb
  • postgresql+asyncpg://localhost/mydb
  • mysql+pymysql://localhost/mydb
  • sqlite:///path/to/file.db

The dialect tells typeddbapi what database you're using, and the optional driver specifies which DB-API 2.0 driver to use. If no driver is specified, the dialect's default driver is used.

Quick Peek

from typeddbapi import connect, ConnectionFactory, Pool

DATABASE_URL = "postgresql+psycopg2://user:pass@localhost/mydb"

# Simple connection
with connect(DATABASE_URL) as conn:
    cursor = conn.cursor()
    cursor.execute("SELECT * FROM users WHERE id = %s", (1,))
    user = cursor.fetchone()
    print(user)

For learning more, look at documentation

Requirements

  • Python 3.7+
  • A DB-API 2.0 compliant driver for your database (install separately)

License

MIT

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

typeddbapi-1.0.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

typeddbapi-1.0.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file typeddbapi-1.0.1.tar.gz.

File metadata

  • Download URL: typeddbapi-1.0.1.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for typeddbapi-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a54efd44494f5bfccae841f7b106b559512c2b0f171e7176f982b6679442515d
MD5 93ec9d031dbffcf8e460ea57b17675e4
BLAKE2b-256 d54cfa5634c1ba956f0aa80986335f8f3b548be5762f7cff7604702f5cd117af

See more details on using hashes here.

File details

Details for the file typeddbapi-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: typeddbapi-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for typeddbapi-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 571e0c3b7703c48acad2def73bdc54996fe5d53888ed03d6aebe623ae8ab4355
MD5 afa2589b59141d57cd02ef6ce408b862
BLAKE2b-256 15a1cdcbaf8007c1208efdae0c409e2d2bf3ff54736a66ab1695c3772cac8828

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