Skip to main content

Configuration via environment

Project description

viaenv - Configuration via Environment for Python

viaenv uses variable annotation to populate values from environment variables.

Example

from datetime import timedelta
from viaenv import populate_from_env


class config:
    port: int = 8080
    log_file: str = '/var/log/server.log'
    timeout: timedelta = timedelta(milliseconds=100)


populate_from_env(
    config, prefix='srv',
    # If you don't pass env, populate_from_env will use os.environ
    env={'SRV_PORT': '9000', 'SRV_TIMEOUT': '300ms'})

print(config.port)  # 9000
print(cfg.timeout == timedelta(milliseconds=300)  # True

Supported Types

  • date: 2019-05-18
  • datetime: 2019-05-18T13:43:12
  • dict: {"x": 1, "y": 2} (JSON format)
  • float: 1.3, 1e7
  • int: 12, 0x12, 0o12, 0b12
  • list: [1, 2, 3] (JSON format)
  • str: Anything goes
  • time: 13:43:12
  • timedelta: 10us, 20ms, 30s, 17m, 2h, 7d, 1h20m

You can add your types by calling

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

viaenv-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file viaenv-0.1.0.tar.gz.

File metadata

  • Download URL: viaenv-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for viaenv-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3b4e0a74e45d31f61a29c5240f5e431b1eb8f2bd7a125c8ab89b297b23262a95
MD5 490df5b67e7eaadfe9831b7b33bcdf3a
BLAKE2b-256 e88f100b8fdfb6de4008091d3ff7026635b12a5e8943434515b457b4cc54d518

See more details on using hashes here.

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