A metaclass for automatically loading and converting environment variables.
Project description
PyEnvloaderMeta - metaclass for automatically loading and converting environment variables into class attributes.
- It simplifies the process of managing environment variables by leveraging type annotations and the
python-dotenvpackage. - Features - Automatically loads environment variables from a
.envfile. - Converts environment variables to specified types using type annotations.
- Raises errors if required environment variables are missing or cannot be converted.
Installation You can install pyenvloader from PyPI using pip:
pip install pyenvloadermeta
Usage
To use pyenvloadermeta, define a class with pyenvloadermeta.EnvLoaderMeta as the metaclass and specify the environment variables with type annotations. Here’s an example:
- Create a
.envfile in your project directory:
.env
API_ID=123456
API_HASH=dfdafdfasdff
BOT_TOKEN=fasdfasfdafsd
OZ=11.2
POKEMON=["Pikachu", "Raichu's"]
- Define your class using
EnvLoaderMeta:
from pyenvloadermeta import EnvLoaderMeta
class Env(metaclass=EnvLoaderMeta):
API_ID: int
API_HASH: str
BOT_TOKEN: str
OZ: float
POKEMON: list[str]
- Access the environment variables as class attributes:
print(Env.API_ID)
print(Env.API_HASH)
print(Env.BOT_TOKEN)
print(Env.OZ)
print(Env.POKEMON)
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
pyenvloadermeta-1.0.2.tar.gz
(2.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyenvloadermeta-1.0.2.tar.gz.
File metadata
- Download URL: pyenvloadermeta-1.0.2.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d934dd5da616ccf7449b66e70faf2d66cbeac4125262e7700bc6441f4ac32a13
|
|
| MD5 |
1e9e1f9e6fde163bf278284d6b4a250c
|
|
| BLAKE2b-256 |
b23c0dbae653a8798b4b3fcba9d4a2e2fe572c54816f665c99aa43e71cc469af
|
File details
Details for the file pyenvloadermeta-1.0.2-py3-none-any.whl.
File metadata
- Download URL: pyenvloadermeta-1.0.2-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
860732b08509eae8cdddddd3fe9f8391abdee4ef74066fe781f55073cff3a79b
|
|
| MD5 |
3514b608e488663e4f00f218b2c6e5a3
|
|
| BLAKE2b-256 |
5860338339596dcccf6fa44ab7b5c0b7d5d38c20227cfb8fb4998af6be50cc6e
|