Skip to main content

Utilities that should've been inside SQLAlchemy but aren't

Project description

sqlalchemy_boltons

SQLAlchemy is great. However, it doesn't have everything built-in. Some important things are missing, and need to be "bolted on".

(Name inspired from boltons. Not affiliated.)

sqlite

SQLAlchemy doesn't automatically fix pysqlite's broken transaction handling. This module implements the usual fix for that well-known broken behaviour, and also adds extra features on top of that.

You can customize, on a per-engine or per-connection basis:

Here's a minimal example:

from sqlalchemy.orm import sessionmaker
from sqlalchemy_boltons.sqlite import create_engine_sqlite

engine = create_engine_sqlite(
    "file.db",
    journal_mode="WAL",
    timeout=0.5,
    create_engine_args={"echo": True},
)

# Configure the engine to use a plain "BEGIN" to start transactions and
# and to use deferred enforcement of foreign keys (recommended!)
engine = engine.execution_options(
    x_sqlite_begin_mode=None, x_sqlite_foreign_keys="defer"
)

# Make a separate engine for write transactions using "BEGIN IMMEDIATE"
# for eager locking.
engine_w = engine.execution_options(x_sqlite_begin_mode="IMMEDIATE")

# Construct a sessionmaker for each engine.
Session = sessionmaker(engine)
SessionW = sessionmaker(engine_w)

# read-only transaction
with Session() as session:
    session.execute(select(...))

# lock the database eagerly for writing
with SessionW() as session:
    session.execute(update(...))

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

sqlalchemy_boltons-1.0.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

sqlalchemy_boltons-1.0.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlalchemy_boltons-1.0.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for sqlalchemy_boltons-1.0.1.tar.gz
Algorithm Hash digest
SHA256 002166e1b046a33389c70b189cbc8cf29f4ebe1f657046b460e139f603907aef
MD5 a2c6d11b673da83b7969b1a6bbca6f33
BLAKE2b-256 4d5f46ab31ed3929e22f50a4d6c7d26cb3cf9bf48ac99cb6649450bafdc34174

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlalchemy_boltons-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5736a492394effcb17fcc0cdc3191a846e58ed0fee4ead22d7dfb2d80591f176
MD5 900c1b419acec9761680459a556b3866
BLAKE2b-256 8e974a7689113b035008175ac2c03bb2a04f5bc3887615f49e8ddadaaca97b90

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