This release is a pre-release and may not be stable for production use.
Getting Started with sqlalchemy-config
version: 0.4.7b0
The sqlalchemy-config package is a toolkit to handle database configuration parameters that are stored in a config file. This can locate, read, and extract the config parameters and create a sessionmaker object from them that is bound to the engine object.
There is online documentation for sqlalchemy-config.
Installation instructions
sqlalchemy-config can be installed via pypi or conda.
Installation using pip
pip install sqlalchemy-config
Installation using conda
I maintain a conda package in my personal conda channel. To install this please run:
conda install -c cfin -c conda-forge sqlalchemy-config
Usage TL;DR
sqlalchemy-config is designed to handle database connection inputs coming from different sources. For example: a URL or SQLite file path on the command line, a config file path from a command-line argument, an environment variable, or a default file in the home directory.
The config files used in the example below have a similar structure to this see SQLAlchemy engine from config:
[mydb_mysql]
# Make sure this is only readable by you
# Make sure password is URL encoded, see: sqlalchemy_config.encode_password
db.url = mysql+pymysql://user:password@127.0.0.1:3306/db_cfg_arg
>>> import sqlalchemy_config as sqlc
>>> import os
>>> # Input from the command line (SQLite file path)
>>> dbarg = "mydb.db"
>>> # Prefix used for SQLAlchemy parameters in config sections
>>> conn_prefix = "db."
>>> # This represents a default location for config files containing parameters
>>> config_file = os.path.join(os.environ['HOME'], "mydbs_def.cnf")
>>> # dbarg is treated as SQLite file path
>>> sqlc.get_new_sessionmaker(dbarg, conn_prefix=conn_prefix, config_arg=config_file)
>>> sessionmaker(class_='Session', bind=Engine(sqlite:///mydb.db), autoflush=True, autocommit=False, expire_on_commit=True)
>>> # dbarg can also be a fully formed SQLAlchemy URL
>>> dbarg = "mysql+pymysql://user:password@127.0.0.1:3306/db_url_arg"
>>> sqlc.get_new_sessionmaker(dbarg)
>>> sessionmaker(class_='Session', bind=Engine(mysql+pymysql://user:***@127.0.0.1:3306/db_url_arg), autoflush=True, autocommit=False, expire_on_commit=True)
See the API documentation for lower level functions.
Development
To set up a development environment, install the package with development dependencies:
pip install -e ".[dev]"
Run the test suite:
pytest tests/ -v
Run tests with coverage reporting:
pytest --cov=sqlalchemy_config --cov-report=term-missing tests/
Verify the coverage threshold (80%) is met:
pytest --cov=sqlalchemy_config --cov-fail-under=80 tests/
Lint and format code before committing:
ruff check --fix . && ruff format .
Change log
See CHANGELOG.md for the full change log.
Release files for sqlalchemy-config 0.4.7b0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sqlalchemy_config-0.4.7b0.tar.gz | 54.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sqlalchemy_config-0.4.7b0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 108.7 kB
Release files / sqlalchemy_config-0.4.7b0.tar.gz
| Download URL | sqlalchemy_config-0.4.7b0.tar.gz |
|---|---|
| Size | 54.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0fd497a8663753922025ef821e0a4fcbe4e922371dc376cb49855c8ae2b10c36
|
|
BLAKE2b-256 checksum How to use checksums |
dc35e7e24ad021d6ce4d6d9ba1efd4d026ae50d833e47941f5d9a83df19a2091
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|
Release files / sqlalchemy_config-0.4.7b0-py3-none-any.whl
| Download URL | sqlalchemy_config-0.4.7b0-py3-none-any.whl |
|---|---|
| Size | 54.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dfa2533c6fcdace3875965dd1082358fee686f3f2fa7b59f95ddc388fed23c46
|
|
BLAKE2b-256 checksum How to use checksums |
a1ff83c8335e7b484aae0052a7ee53f2e0c101f83c544ab24df4404e0f20a5db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|