Classy Env is a lightweight python package for managing environment variables in OOP way.
Project description
Classy Env
About
Classy Env is a lightweight Python package for managing environment variables in an OOP way.
Requirements
This package requires Python 3.11 or higher.
Installation
Classy Env is available on PyPI and can be installed by running the following command:
pip install classy-env
Usage
Create a ClassyEnv
subclass and declare its attributes using the EnvVar
function:
from classyenv import ClassyEnv, EnvVar
class Settings(ClassyEnv):
database_user = EnvVar("DB_USER")
database_password = EnvVar("DB_PASSWORD")
api_secret_key = EnvVar("SECRET_KEY")
The EnvVar
function takes the name of the environment variable as an argument.
The Value of that variable will be assigned to the corresponding attribute.
Then, create an object of your subclass and access the environment variables through the object's attributes:
settings = Settings()
database_connection = connect(
user=settings.database_user,
password=settings.database_password,
)
At the object's creation, Classy Env will check if the environment variables
provided to the EnvVar
functions are defined. If not, an exception will be raised.
This validation can also be triggered at class creation using the runtime_check
class argument:
from classyenv import ClassyEnv, EnvVar
class Settings(ClassyEnv, runtime_check=True):
database_user = EnvVar("DB_USER")
database_password = EnvVar("DB_PASSWORD")
api_secret_key = EnvVar("SECRET_KEY")
Mutating the ClassyEnv
instances and subclasses
At this moment, mutating instances of the ClassyEnv
class is not supported:
settings.database_user = "Roe_Jogan123" # this will raise an exception
Similarly, mutating the class attributes of the ClassyEnv
subclasses is not supported:
Settings.database_user = "Roe_Jogan123" # this will raise an exception
License
This project is licensed under the terms of the MIT license.
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
Built Distribution
Hashes for classy_env-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2669a38b859200223e21a11b5a118a5493c63ccdbc6f22b03249ab365c5936b |
|
MD5 | f78b8d0bae7bf68eb283ef44df6ab0e0 |
|
BLAKE2b-256 | 7fbfad796853c75a3694665dfc3b031eaa834a85c219a8490796810428c3a699 |