An abstract configuration object used to facilitate building flexible configs from environment variables
Project description
flexenvconfig
A common pattern that I use across many of my Python apps/packages/etc is to use configuration classes that fetch my configs from the environment. Because each project may use different configurations, and different parts of a project (the database, for example) might have specific configurations, I created this package which provides an abstract class as a base to build flexible environmental configuration objects.
Here is an example:
from flexenvconfig import BaseFlexEnvConfig
class MongoDBConfig(BaseFlexEnvConfig):
def __init__(self) -> None:
self.MONGO_DB_NAME = MongoDBConfig.get_env("MONGO_DB_NAME", "testdb")
self.MONGO_DB_HOST = MongoDBConfig.get_env("MONGO_DB_HOST", "localhost")
self.MONGO_DB_PORT = int(MongoDBConfig.get_env("MONGO_DB_PORT", "12345"))
self.MONGO_DB_USERNAME = MongoDBConfig.get_env("MONGO_DB_USERNAME", "mongouser")
self.MONGO_DB_PASSWORD = MongoDBConfig.get_env("MONGO_DB_PASSWORD", "mongopassword")
self.OPTIONAL_CONFIG = MongoDBConfig.get_env("OPTIONAL_CONFIG")
def validate(self) -> bool:
return all([self.MONGO_DB_NAME, self.MONGO_DB_HOST, self.MONGO_DB_PORT, self.MONGO_DB_USERNAME, self.MONGO_DB_PASSWORD])
BaseFlexEnvConfig
's constructor defines the configs which gets sourced from the environment when implemented. When implemented, the validate
method is used to validate that a config object contains the required values.
Development
You'll need poetry and Python 3.11+. Clone the repo and then run poetry install
Then you'll need to install the pre-commit hooks: poetry run pre-commit install
You can run the test suite using make test
and you can manually lint the project using make lint
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file flexenvconfig-1.0.0.tar.gz
.
File metadata
- Download URL: flexenvconfig-1.0.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.2 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9cbadff7a52b0975b4a7b148343145cecd4dc9f9115ab81aecdee32cdafccce |
|
MD5 | c600f3a884f58d3e7308a4c7a958abb6 |
|
BLAKE2b-256 | 2987cc747ad06237c556ecd76dbbbec3cf4656ee56c1c9f4bb45ba0d8d280016 |
File details
Details for the file flexenvconfig-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: flexenvconfig-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.2 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5f052b3fe6c5cbadc26cca78082f29da840fa6842a4730a22cc84ea913afde1 |
|
MD5 | 643e0bdbd0025440eb2759210b46af86 |
|
BLAKE2b-256 | 13a660dec94a0734d728634fae293ed162e58b1fa76f7e7005f6ee901d0ed827 |