Skip to main content
https://github.com/gtmanfred/figenv/workflows/Tests/badge.svg https://img.shields.io/codecov/c/github/gtmanfred/figenv https://img.shields.io/pypi/v/figenv https://img.shields.io/pypi/l/figenv https://img.shields.io/pypi/dm/figenv

Metaclass for handling configuration class objects using environment variables.

If an environment variable is specified, the metaclass will pull the variable from the environment, the variable defined on the class will be used.

This was built to be a dropin replacement for flask-env but supporting change environment variables after the meta class is loaded.

Config

There are 2 configuration options, that are set on the base class object.

ENV_LOAD_ALL = <True/False>

Setting this on the class will allow loading any environment variable even if it is not set on the base class.

ENV_PREFIX = <string>

Setting this will will be a prefix for variables in the environment.

Install

This should just be pip installed

python3 -m pip install figenv

Usage

The basic usecase is below.

 import os

 import figenv

 class Config(metaclass=figenv.MetaConfig):

     ENV_LOAD_ALL = True
     ENV_PREFIX = 'ROCKSTEADY_'

     BLAH = True
     TIMEOUT = 5
     POSTGRES_HOST = 'localhost'
     POSTGRES_PORT = 5432
     POSTGRES_USER = 'bebop'
     POSTGRES_PASS = 'secret'
     POSTGRES_DB = 'main'

     def SQLALCHEMY_DATABASE_URI(cls):
         return 'postgresql://{user}:{secret}@{host}:{port}/{database}?sslmode=require'.format(
             user=cls.POSTGRES_USER,
             secret=cls.POSTGRES_PASS,
             host=cls.POSTGRES_HOST,
             port=cls.POSTGRES_PORT,
             database=cls.POSTGRES_DB,
         )

assert Config.TIMEOUT == 5
assert Config.BLAH is True
assert Config.SQLALCHEMY_DATABASE_URI == 'postgresql://bebop:secret@localhost:5432/main?sslmode=require'
try:
    Config.WHAT
except AttributeError:
    pass

os.environ.update({
    'ROCKSTEADY_BLAH': 'false',
    'ROCKSTEADY_TIMEOUT': '15',
    'ROCKSTEADY_WHAT': '2.9',
    'ROCKSTEADY_SQLALCHEMY_DATABASE_URI': 'postgres://localhost:5432/db',
})

assert Config.TIMEOUT == 15
assert Config.BLAH is False
assert Config.WHAT == 2.9
assert Config.SQLALCHEMY_DATABASE_URI == 'postgres://localhost:5432/db'

Download files

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

Source Distribution

figenv-1.0.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

figenv-1.0.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file figenv-1.0.0.tar.gz.

File metadata

  • Download URL: figenv-1.0.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for figenv-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f40e090c8981d51720484989550a22cc77bd453f64526511c187d40d9dbaddc3
MD5 a9c39ba93a8361a5a10f2f34491abc6c
BLAKE2b-256 57bd549c69743949f2a8dfaa9fc08990c6eb106d89bfad89b6c9bc3468c931ee

See more details on using hashes here.

File details

Details for the file figenv-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: figenv-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for figenv-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 673ee178fa0d469700389359c92c45c1894e7f49c646878b97e23d428496871b
MD5 f6c113402eabd9e5b55f4d1c8a11621b
BLAKE2b-256 d61c4869197bd77accd7c1c27100d1ad91788e1b1b0be5e4e7c7ba1072ca2537

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page