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 environment variables into class variables by variable name
- Configuring the loading of changes using a variable of class
meta
Installation
You can use your favorite package manager to install/update the lenv
package. For example, pip
, as in this example:
python3 -m pip install -U python-lenv
Usage/Examples
dotenv
First of all, let's define our .env
file, which will be located in the startup directory of the main file.
I put the TOKEN
and API_KEY
there, in the future we will be able to get them through class variables
TOKEN=FOlCLYqcM.ZRgpwq.IrUyWYwjwSvFmCITCbmOBqvbqpZLWNrufvQKsrawplHMAwICSjBJvSlkJFaeENCrYkdOUeqSwmwQoMbTEJLLFLIGDLXaWF.HsNqciQnXitjhzXO
API_KEY=a3edffac-f4cc-4e68-9fd3-11e942fc7ea6
python
Finally, we come to our first example. We can use class variables to get environment variables directly through the class.
import lenv
class Config(lenv.EnvironmentLoader):
# This configuration is not important, the default is used `lenv.DefaultMetadata`
# which has a file path like .env in it. But for example, let's leave it
meta = lenv.ConfigurableMetadata(dotenv_path=".env")
# These class variables will be used directly to access environment variables -O-
TOKEN: str
API_KEY: str
assert Config.TOKEN == 'FOlCLYqcM.ZRgpwq.IrUyWYwjwSvFmCITCbmOBqvbqpZLWNrufvQKsrawplHMAwICSjBJvSlkJFaeENCrYkdOUeqSwmwQoMbTEJLLFLIGDLXaWF.HsNqciQnXitjhzXO'
assert Config.API_KEY == 'a3edffac-f4cc-4e68-9fd3-11e942fc7ea6'
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
File details
Details for the file python_lenv-0.5.0.tar.gz
.
File metadata
- Download URL: python_lenv-0.5.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3de753d6e1654d54147508e701deef81e1480754006349bd975da3456050b809 |
|
MD5 | e355519bf8f4fde7a2d6621fdb8878a6 |
|
BLAKE2b-256 | 0b2927e040f62d55a9258548288916f79e35e067c70508d21367a06226b8a3bb |
File details
Details for the file python_lenv-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: python_lenv-0.5.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad97638d47df0a5603511b7407d8dc8c0acf35b921cf18d04f4bdaeca66b9b6c |
|
MD5 | aa858f5b922f2baf902a39a6a1ad2089 |
|
BLAKE2b-256 | bfca5a3b97140dc7d8c751727805380b6b14df050d6802bf840901d9b8d3616e |