Skip to main content

Figenv

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 https://readthedocs.org/projects/figenv/badge?version=latest&style=flat

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'

Metadata

Release files for figenv 1.6.1

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

Source distribution (sdist)

Source distribution for figenv 1.6.1
File Size Uploaded
figenv-1.6.1.tar.gz 14.4 kB Details

Built distribution (wheel)

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

Total release size: 19.7 kB

Release files / figenv-1.6.1.tar.gz

Download URL figenv-1.6.1.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
27e7e3eca86ff2c5d5bec0c76df73f285d9fd77589b288e64916238e11be15b6
BLAKE2b-256 checksum
How to use checksums
b3e32bdb0738af2e675ca94ff632cd33955b5c6ee601b4e363b71378353a7ac5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / figenv-1.6.1-py3-none-any.whl

Download URL figenv-1.6.1-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e3a0266894010c5c02d674210be2af3491563536aa3e9dccca056105b89397d
BLAKE2b-256 checksum
How to use checksums
8a9f86345a04814e2c21964898306cb3ba5a3ff6d44accad6fff77be7f3f8850
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

1.6.1 This release

2 release files

1.6.0

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

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