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.4.0.tar.gz
.
File metadata
- Download URL: python_lenv-0.4.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77188e5537b605092b995d8ca0a84c906a045ff2de6574444e58f735b550317b |
|
MD5 | 070e58900afd654d137652997ed7dd11 |
|
BLAKE2b-256 | 3c7b73c0c6fa97916792566b226f7978ba98db6fc09371fced6c0fe9d065a163 |
File details
Details for the file python_lenv-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: python_lenv-0.4.0-py3-none-any.whl
- Upload date:
- Size: 4.6 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 | 231443dc51655c5e3aba9490c30f2213063d6942fa49a66e2d175bc053b259a1 |
|
MD5 | dac489f4dc8389c8e979d882c884d193 |
|
BLAKE2b-256 | 68cb4adbd0aa3f5f35d95b60644421e0469bb414be205341999149a192bf8ade |