Skip to main content

configur8

Python type-safe configuration and validation library.

Introduction

Configuration validation is a common problem in Python. This library aims to provide a simple, type-safe way to validate configuration either by file or environment variables.

An example:

/path/to/config.yaml:

mysql:
   host: localhost
   port: 3306
   user: not_root
   password: my_password
import configur8
from configur8 import env


class MySQL:
   # define the fields and their types
   host: str
   # default values are supported
   port: int = 3306
   # default values can programmatically be defined, e.g. from an env var
   user: str = env.str("MYSQL_USER", "definitely_not_root")
   password: str


class Config:
   mysql: MySQL


config = configur8.load(Config, "/path/to/config.yaml")

assert isinstance(config.mysql, MySQL)  # True

The above example will load the configuration from the file at /path/to/config.yaml and validate it against the Config class. If the configuration is invalid, an exception will be raised.

Environment only

An example:

from configur8 import env


SECRET_KEY = env.str("SECRET_KEY")
NUM_WORKERS = env.int("NUM_WORKERS", 2)
DEBUG = env.bool("DEBUG", False)

In the example above:

  1. SECRET_KEY is a required environment variable - attempting execute the code without it defined will result in an exception. This is typically what you want so that apps and services don't start in an unintended state.
  2. NUM_WORKERS will be parsed into an integer. If the env var is not defined, 2 will be used as a default. If a non integer value is parsed, an error will be raised.
  3. DEBUG is a boolean with a default of False. "Truthy" values can be used, e.g. "on", "1", etc.

Everything is designed to be type safe.

Types of values supported

  • String - env.str
  • Integer - env.int
  • Float - env.float
  • Boolean - env.bool
  • Url - env.url
  • Path - env.path
  • Email - env.email - Validation provided by email-validator Each type can support optional values and work with lists:
from configur8 import env

ALLOWED_HOSTS = env.url.list("ALLOWED_HOSTS")

Given the environment:

ALLOWED_HOSTS=http://localhost,http://my-staging-server

The python value of ALLOWED_HOSTS would be:

["http://localhost", "http://my-staging-server"]

Boolean flags

Boolean values are supported. See configur8.env.BOOLEAN_TRUTHY_VALUES:

  • true
  • 1
  • on
  • yes
  • ok

Will all result in a True Python value. Anything else will result in False.

Urls

These are augmented objects that have extra attributes in case you need them:

from configur8 import env

# https://my-bucket.s3.us-west-2.amazonaws.com
bucket = env.url("S3_BUCKET_URL")

assert bucket.protocol == "https"
assert bucket.host == "my-bucket.s3.us-west-2.amazonaws.com"

There are a bunch more properties - see configur8.url.Url.

Paths

These are augmented objects that have extra attributes in case you need them:

from configur8 import env

# /var/run/secrets/my-mounted-volume/my-secret
my_creds = env.path("SERVICE_CREDS").read()

# my_creds will hold the contents of the file in the env var

Development

  1. Install PDM
  2. Install Task

Running tests

task test

Publishing to PyPI

NOTE Replace __VERSION__ with a semver identifier such as 0.9.3

  1. Ensure that you are on a clean master.
  2. Update __version__ in src/configur8/__about__.py to __VERSION__.
  3. Update CHANGELOG.md with the new version and changes.
  4. git add src/configur8/__about__.py CHANGELOG.md
    git commit -m "Bump to __VERSION__"
    git tag v__VERSION__
    git push origin --tags
    
  5. Wait for Github Actions to succeed and publish the library to the public PyPI.

Metadata

Release files for configur8 2.2.0

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

Source distribution (sdist)

Source distribution for configur8 2.2.0
File Size Uploaded Provenance
configur8-2.2.0.tar.gz 14.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for configur8 2.2.0
File Interpreter ABI Platform
configur8-2.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.8 kB

Release files / configur8-2.2.0.tar.gz

Download URL configur8-2.2.0.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2dc967d5b6539adf20eb81e5f635df9ee9b262685c8255f9ecb147ca329f720d
BLAKE2b-256 checksum
How to use checksums
54fb609e6a48fbee987190a43d4010e6401fe3ba9c59e996b3fda5cccabf1adb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.22.3 CPython/3.13.2 Darwin/24.3.0

Release files / configur8-2.2.0-py3-none-any.whl

Download URL configur8-2.2.0-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7434b4479b8e1ff4b1ae792ffbccad52420f421ce54a88f2f93a332d9dc58b2
BLAKE2b-256 checksum
How to use checksums
dd55f1db33a225278f5b3ff544394c9b1750b3894fbec008b1088acaf03ffcc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.22.3 CPython/3.13.2 Darwin/24.3.0

Security for configur8 2.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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