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
  • 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.3

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.3
File Size Uploaded
ga_configreader-0.1.3.tar.gz 12.5 kB Details

Built distribution (wheel)

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

Total release size: 20.5 kB

Release files / ga_configreader-0.1.3.tar.gz

Download URL ga_configreader-0.1.3.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7c3ae5842bbea04e0b423075507d1b22b4b8795ef4c6b477c059bae7c6364911
BLAKE2b-256 checksum
How to use checksums
5e418dff53208a4b751840082e6e7a2c74c1f08e78759b8ad4f7202420884bbf
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 3, 2026.

Transparency log

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

Download URL ga_configreader-0.1.3-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97894ce49fbf7cf07fdf3576e9ca44a6a6b403a5d53b5d59958ef3f6d9c3d5dc
BLAKE2b-256 checksum
How to use checksums
2f5a83fc865dfd68ff4db91547515c85ea0fa854be10a53636847bcb7d794e78
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 3, 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

0.1.4

2 release files

This release

0.1.3 This release

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