Skip to content

Configuration parsing library from environment variables

License

Notifications You must be signed in to change notification settings

illuin-tech/enviparse

Folders and files

NameName
Last commit message
Last commit date
Nov 18, 2024
Aug 23, 2024
Aug 23, 2024
Aug 23, 2024
Aug 23, 2024
Aug 23, 2024
Aug 23, 2024
Aug 23, 2024
Aug 23, 2024
Feb 1, 2024
Mar 3, 2025

Repository files navigation

Enviparse

CI codecov

Description

Enviparse let you simply create dataclasses from environment variable.

Supported types are :

  • int
  • float
  • str
  • bool
  • optional
  • list
  • enum (with int or string values only)
  • @attr annotated class
  • @dataclasses.dataclass annotated class

Example

With following environment variables :

DATABASE_CONFIG_USERNAME=postgres
DATABASE_CONFIG_PASSWORD=password
DATABASE_CONFIG_HOST=127.0.0.1
DATABASE_CONFIG_PORT=5432
DATABASE_CONFIG_DATABASE_NAME=appdb

You can parse environment variable with :

import dataclasses
from enviparse import Enviparse


@dataclasses.dataclass
class DatabaseConfig:
    username: str
    password: str
    host: str
    port: int
    database_name: str


db_config = Enviparse().parse("DATABASE_CONFIG", DatabaseConfig)
print(db_config)

You should get the following result :

DatabaseConfig(username='postgres', password='password', host='127.0.0.1', port=5432, database_name='appdb')

For more example see the test folder.