Quickly and efficiently load environment variables into a class
Project description
python-lenv
Welcome to the lenv package page! This package allows you to quickly, efficiently and conveniently load environment variables into a class!
Features
- Loading variables into a class by variable name
- Loading variables into a class by variable value
- Configurability using
metadata
- Documentation
Installation
To install/update the lenv
package, you need to use pip
python3 -m pip install -U python-lenv
Usage/Examples
First, we'll look at the structure of your project, which should look like this
my-awesome-project
├── .env
└── main.py
Let's go to the file where the variables will be loaded into your class. We will name it .env
and put the following content inside
KEY=value
Let's move on to the most important thing, namely our python script where environment variables will be loaded from the .env
file we created earlier
# main.py
from lenv import Meta
class Environ(metaclass=Meta):
# Metadata allows you to configure the settings for loading environment variables.
metadata = {
# To see the available configurable options, you can view the `load_dotenv` function signature
# https://github.com/theskumar/python-dotenv/blob/main/src/dotenv/main.py#L321-L328
"load_dotenv": {
"dotenv_path": "./venv/.env",
...: ...
}
}
# Normal retrieval of a value. We can get the value of an environment variable
# using the name of the variable, this is the most common use case
NAME: str
# Also, we can get the environment variable not by the variable name, but by the value of the variable
Name: int = "NAME" # <- This is the key by which the value of the environment variable will be sufficient
# We can use typehints as below to convert the received
# environment variable to a Python data type
AGE: int
# We can also use other types, such as list
API_KEYS: list
License
lenv
is distributed 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 python_lenv-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7bad44fe2acf2f53736358221bba688d2c2b7d6aaa20e97e2249cb8ed7ae2ea |
|
MD5 | 9ee95887e538c0f31b8b94f786746d66 |
|
BLAKE2b-256 | bece46f2166a6f41e3c7eb01684e6c485ef763d77835cb4ae06a841fa92826d5 |