Skip to main content

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,
    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:

  1. check environment first
  2. then check database
  3. then check INI file
  4. then check dictionary

Environment Variables

Naming rules:

  • if section="DEFAULT", variable name is NAME
  • for custom sections, variable name is SECTION_NAME

Examples:

  • reader.get("host", section="DEFAULT") reads HOST
  • reader.get("host", section="app") reads APP_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 | None
  • getint(name, default=None, section="DEFAULT") -> int | None
  • getboolean(name, default=None, section="DEFAULT") -> bool | None
  • getfloat(name, default=None, section="DEFAULT") -> float | None
  • getlist(name, default=None, section="DEFAULT") -> list[Any] | None
  • getset(name, default=None, section="DEFAULT") -> set[Any] | None
  • gettuple(name, default=None, section="DEFAULT") -> tuple[Any, ...] | None
  • getdict(name, default=None, section="DEFAULT") -> dict[Any, Any] | None
  • sections() -> list[str] merged section names across enabled providers
  • variables(section) -> list[str] merged variable names for a section across enabled providers
  • get_sections(section) -> list[str] backward-compatible alias for variables(section)
  • items() iterator over loaded INI entries

Full details in docs/api.md.

Errors And Type Conversion

  • FileNotFoundError is 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.

Release files for ga-configreader 0.1.4

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

Source distribution (sdist)

Source distribution for ga-configreader 0.1.4
File Size Uploaded
ga_configreader-0.1.4.tar.gz 13.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ga-configreader 0.1.4
File Interpreter ABI Platform
ga_configreader-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 22.6 kB

Release files / ga_configreader-0.1.4.tar.gz

Download URL ga_configreader-0.1.4.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
63df2fad526f5df8a81c5e7595f58658f28ffba088e84eeffda428d7cf790f33
BLAKE2b-256 checksum
How to use checksums
7abd45a039dcfbf2dd969a13cf093193b17b6f0635cd0007ed22dfe9f3932daf
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

Release files / ga_configreader-0.1.4-py3-none-any.whl

Download URL ga_configreader-0.1.4-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2228c56affece6433e380d45b9a1d98a86fe7166a27138ae5849d513c431520f
BLAKE2b-256 checksum
How to use checksums
f3048276ddf53b9f61351a39b84eb061e627a87fd923b8b3720710e01a4b891d
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

Release history Release notifications | RSS feed

0.2.6

2 release files

0.2.3

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.7

2 release files

This release

0.1.4 This release

2 release files

0.1.3

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