configreader
Python library to read configuration values from multiple sources with configurable precedence.
Supported sources:
- INI file
- SQL database through SQLAlchemy (optional)
- environment variables
- in-memory Python dictionary
Values are resolved in order, and the first non-empty match is returned.
Installation
From PyPI
pip install ga-configreader
From source
git clone https://github.com/andreagemma/configreader.git
cd configreader
pip install -e .
Database support (optional)
Install SQLAlchemy if you want to use the DB provider:
pip install sqlalchemy
Or install the project with DB extras:
pip install "configreader[db]"
Quickstart
from configreader import ConfigReader
reader = ConfigReader(
file="config.ini",
use_env=True,
env_default_section="APP",
dictionary={"DEFAULT": {"timeout": "30"}},
providers=["env", "ini", "dict"],
)
host = reader.get("host", default="127.0.0.1")
port = reader.getint("port", default=8080)
debug = reader.getboolean("debug", default=False)
Provider Precedence
The providers list defines lookup order.
Example:
providers = ["env", "db", "ini", "dict"]
Meaning:
- check environment first
- then check database
- then check INI file
- then check dictionary
Environment Variables
Naming rules:
- environment variables are read as SECTION_NAME, using the requested section name as prefix
- with the default section, this means DEFAULT_NAME unless you set env_default_section or pass an empty section
Examples:
- reader.get("host") reads DEFAULT_HOST
- reader.get("host", section="app") reads APP_HOST
- ConfigReader(env_default_section="APP").get("host") reads APP_HOST
- reader.get("host", section="") reads HOST first, then DEFAULT_HOST
Using INI Files
Example config.ini:
[DEFAULT]
host = localhost
port = 5432
debug = true
items = [1, 2, 3]
[app]
workers = 4
Code:
reader = ConfigReader(file="config.ini")
host = reader.get("host")
port = reader.getint("port")
debug = reader.getboolean("debug")
items = reader.getlist("items")
workers = reader.getint("workers", section="app")
Using a Dictionary
reader = ConfigReader(
dictionary={
"DEFAULT": {
"host": "localhost",
"allowed": "['admin', 'user']",
},
"service": {
"retries": "3",
},
},
providers=["dict"],
)
allowed = reader.getlist("allowed")
retries = reader.getint("retries", section="service")
Using a Database
Constructor:
reader = ConfigReader(
db_url="sqlite:///settings.db",
db_query="SELECT value FROM settings WHERE section = :section AND name = :name",
providers=["db", "env"],
)
Default query shape:
SELECT value FROM settings WHERE section = :section AND name = :name
DB utility methods:
ok = ConfigReader.check_db_connection("sqlite:///settings.db")
exists = ConfigReader.check_db_exists("sqlite:///settings.db", table_name="settings")
Main API
get(name, default=None, section="DEFAULT") -> str | Nonegetint(name, default=None, section="DEFAULT") -> int | Nonegetboolean(name, default=None, section="DEFAULT") -> bool | Nonegetfloat(name, default=None, section="DEFAULT") -> float | Nonegetlist(name, default=None, section="DEFAULT") -> list[Any] | Nonegetset(name, default=None, section="DEFAULT") -> set[Any] | Nonegettuple(name, default=None, section="DEFAULT") -> tuple[Any, ...] | Nonegetdict(name, default=None, section="DEFAULT") -> dict[Any, Any] | Nonesections() -> list[str]merged section names across enabled providersvariables(section) -> list[str]merged variable names for a section across enabled providersget_sections(section) -> list[str]backward-compatible alias forvariables(section)items()iterator over loaded INI entries
Full details in docs/api.md.
Errors And Type Conversion
FileNotFoundErroris raised if the provided INI file does not exist.- Typed getters (
getint,getfloat,getlist, etc.) propagate parsing/conversion errors. - If SQLAlchemy is not installed, DB features are unavailable.
Development
Install development dependencies:
pip install -e .[dev]
Run tests:
pytest
More Documentation
License
Distributed under the MIT License. See LICENSE.
Third-party dependency notices and archived license files are available in:
Release files for ga-configreader 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ga_configreader-0.1.7.tar.gz | 25.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ga_configreader-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.8 kB
Release files / ga_configreader-0.1.7.tar.gz
| Download URL | ga_configreader-0.1.7.tar.gz |
|---|---|
| Size | 25.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
be106134c016890389fb0b738b71588f96d549703d9076290333ea48ea4914d7
|
|
BLAKE2b-256 checksum How to use checksums |
f84f90ed51bfd1d2488e4f72a9b3df483bb3da8e2342a9f0ff0415b66c03af25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.
Transparency logRelease files / ga_configreader-0.1.7-py3-none-any.whl
| Download URL | ga_configreader-0.1.7-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e62a91da1e5589b09d5437d00f81361d49d664e9b57c9a7ee4ae74e3ff1e2d77
|
|
BLAKE2b-256 checksum How to use checksums |
41883db4ecc57c3af734d7c7fa6af70f51ac5cfce605347f733fb6ed891465f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.
Transparency log