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-dotenv
package. - Features - Automatically loads environment variables from a
.env
file. - 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
.env
file in your project directory:
.env
API_ID=123456
API_HASH=dfdafdfasdff
BOT_TOKEN=fasdfasfdafsd
OZ=11.2
- Define your class using
EnvLoaderMeta
:
from pyenvloadermeta import EnvLoaderMeta
class Env(metaclass=EnvLoaderMeta):
API_ID: int
API_HASH: str
BOT_TOKEN: str
OZ: float
- Access the environment variables as class attributes:
print(Env.API_ID)
print(Env.API_HASH)
print(Env.BOT_TOKEN)
print(Env.OZ)
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.1.tar.gz
(2.4 kB
view details)
Built Distribution
File details
Details for the file pyenvloadermeta-1.0.1.tar.gz
.
File metadata
- Download URL: pyenvloadermeta-1.0.1.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a1d85c72404c97b72ef3eee7da37ae077248d11413d4fc67b563108737a73ab |
|
MD5 | 7718cf7b79abb4ccea9924328ced86e9 |
|
BLAKE2b-256 | dc009ae2173212ed7576089c3b6457d1224a20cda32531a11793fad2c196e3d1 |
File details
Details for the file pyenvloadermeta-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: pyenvloadermeta-1.0.1-py3-none-any.whl
- Upload date:
- Size: 2.5 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 | f3cd2d1ccc0a38ccfe7d3a573af58578f5e1f0e8c5cc537ca4d375a8f4351d00 |
|
MD5 | 5e62e380fe88677b330f62bebe69d5e0 |
|
BLAKE2b-256 | cc94654ed1363282eed2e5939855f687771b1e9a660627ebcdea8bffc4824c9c |