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_DATABASE,
)
assert Config.TIMEOUT == 5
assert Config.BLAH is True
assert Config.SQLALCHEMY_DATABASE_URI == 'postgresql://bebop:secret@localhost:5432/public?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 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| figenv-0.2.0.tar.gz | 3.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| figenv-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.9 kB
Release files / figenv-0.2.0.tar.gz
| Download URL | figenv-0.2.0.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a3bf543d26dbcfbfcae7c57531ba74a1af46c9d1e13525601bc6149fcd44edc5
|
|
BLAKE2b-256 checksum How to use checksums |
4436feefb059e926f14db9c3a3325387f4f6e30d563bd71486a674606637ebc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
|
Release files / figenv-0.2.0-py3-none-any.whl
| Download URL | figenv-0.2.0-py3-none-any.whl |
|---|---|
| Size | 3.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
371d6a51cba76b59ef6d02d4fe7d837dd8f720ccc3a1d22439eabc4a526c8008
|
|
BLAKE2b-256 checksum How to use checksums |
eb75fa58090b9be6a62b47bd72b2d653b927050270e4841e14547c4fdaaa0f1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
|
Security for figenv 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.