Skip to main content

tinkerfin-sqlalchemy

Async transaction support for storage integrations using SQLite, MySQL, or PostgreSQL. Application code normally uses a TinkerFin Store and supplies its own SQLAlchemy AsyncEngine; storage integrations use SqlTransaction directly.

Installation

pip install tinkerfin-sqlalchemy

Python 3.11 or newer is required. Install an asynchronous database driver such as aiosqlite, asyncmy, or asyncpg.

Quick Start

Install the driver for this in-memory example:

pip install aiosqlite
import asyncio

from sqlalchemy import text
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.pool import AsyncAdaptedQueuePool

from tinkerfin_sqlalchemy import SqlTransaction


async def main() -> None:
    engine = create_async_engine(
        "sqlite+aiosqlite:///:memory:",
        poolclass=AsyncAdaptedQueuePool,
        pool_size=1,
        max_overflow=0,
    )
    try:
        async with SqlTransaction(engine, schema_lock="example-balances") as connection:
            await connection.execute(
                text("CREATE TABLE balances (amount INTEGER NOT NULL)")
            )
            await connection.execute(text("INSERT INTO balances (amount) VALUES (0)"))

        async with SqlTransaction(engine) as connection:
            await connection.execute(text("UPDATE balances SET amount = amount + 1"))

        async with SqlTransaction(engine, read_only=True) as connection:
            result = await connection.execute(text("SELECT amount FROM balances"))
            print(result.scalar_one())
    finally:
        await engine.dispose()


asyncio.run(main())

Successful writes commit; failed writes roll back. Reads share one database snapshot. The Engine remains owned by the caller. Temporary lock settings are restored before connections return to the pool; connections that cannot be restored are discarded. Cancellation waits for connection cleanup. Driver timeouts remain host configuration.

Connections must have exclusive pool checkouts. File-based SQLite engines use this by default. For an in-memory SQLite database, configure AsyncAdaptedQueuePool with pool_size=1 and max_overflow=0; StaticPool shares one live connection across transactions and is rejected. Discarding an in-memory connection also discards its data.

For schema setup, supply a stable schema_lock name and run DDL on the yielded connection. Integrations keep their own schema, retry policy, and commit confirmation. SqlTransaction performs one attempt and never replays application work.

Documentation

TinkerFin documentation

License

Apache-2.0

Metadata

Release files for tinkerfin-sqlalchemy 0.1.1

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

Source distribution (sdist)

Source distribution for tinkerfin-sqlalchemy 0.1.1
File Size Uploaded
tinkerfin_sqlalchemy-0.1.1.tar.gz 18.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tinkerfin-sqlalchemy 0.1.1
File Interpreter ABI Platform
tinkerfin_sqlalchemy-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 36.5 kB

Release files / tinkerfin_sqlalchemy-0.1.1.tar.gz

Download URL tinkerfin_sqlalchemy-0.1.1.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5087faf0432d2dbae4f8b12ace02a0ae955d1a74814c4bd69ab382483f0a52ad
BLAKE2b-256 checksum
How to use checksums
87c3003535cca58e322abd8b9ccf43d7422fae5136aa852f3dcd66742dd07de6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / tinkerfin_sqlalchemy-0.1.1-py3-none-any.whl

Download URL tinkerfin_sqlalchemy-0.1.1-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3a2a8743043e7996aa5b2336b97980c59437d82ddb14cec3e11919094f70411
BLAKE2b-256 checksum
How to use checksums
44239bbbe31b0a43f8d57a438b3146d222bb2e3f277a9edfb2492c9bede09251
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

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