Skip to main content

enviparse help you manage your application properties using environment variabl

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

enviparse-2.0.1.tar.gz (14.6 kB view hashes)

Uploaded Source

Built Distribution

enviparse-2.0.1-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page