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. Instead, it provides a recipe for doing so inside the documentation. This module implements a fix for that broken behaviour.

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

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})

# use standard "BEGIN" and use deferred enforcement of foreign keys
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")

Session = sessionmaker(engine)
SessionW = sessionmaker(engine_w)

with Session() as session:
    session.execute(select(...))

# this locks the database eagerly
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.0.tar.gz (9.1 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.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlalchemy_boltons-1.0.0.tar.gz
  • Upload date:
  • Size: 9.1 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.0.tar.gz
Algorithm Hash digest
SHA256 48bcd3f25e286273894b8224ddd138d2d55bb17c7330b2c9417ea21c7525836d
MD5 64d82c2d193e3798244f83fd63eb6b2d
BLAKE2b-256 0f5a3608a486f2875e624e66d425fae49dda883704bf8827fa4cb412139e63cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlalchemy_boltons-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24bba26c1610c42cbe275a04d1ac8ed675927100da1b30e2b485fb905c2b3c66
MD5 bb007075a52842601a5466abf272060e
BLAKE2b-256 d663cd08fa03cab1704e6df969126abc9f58f41698ffc0265ed9e334e1fbaca5

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