A minimal module for working with dotenv files.
Project description
dotenv
A minimal module for working with dotenv files.
Examples
>>> from dotenv import load_dotenv, getenv
>>> load_dotenv()
Load the dotenv file from .env. If any error occurs, nothing will happen.
However, if the value is being retrieved from a load_dotenv() call:
>>> env = load_dotenv()
>>> print(env) # `None` if all is alright.
>>> print(env) # In case of `Exception`, Houston, we have a problem.
>>> load_dotenv(verbose=True)
In this case, if there's an exception, the function will raise it.
>>> key: str = getenv("API_KEY")
getenv() returns the value from the environment by the key if it exists.
If the key doesn't exist, getenv() will raise a KeyError.
To avoid this exception:
>>> max_connections: Union[str, int] = getenv("MAX_CONNECTIONS", default=100)
You can pass any value as the default argument, which prevents the exception!
However, as you can see, max_connections might be str, which could be problematic.
To avoid this, getenv() provides a way to cast the result:
>>> max_connections: int = getenv("MAX_CONNECTIONS", into=int)
Now max_connections will be of type int.
Installation
> pip install git+https://github.com/stefanlight8/dotenv
Requirements
- Python 3.6<
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
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 minenv-0.1.0.tar.gz.
File metadata
- Download URL: minenv-0.1.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed3b7426ff7272c689241e836a2771eb85783d37a075cffecbb4eec5cc9e85bf
|
|
| MD5 |
333e62ed34090399a113a6b6eee73b02
|
|
| BLAKE2b-256 |
e52604ad85af412942cf188aaa53cee750db7a0e69932018ed3a20c02969b406
|
File details
Details for the file minenv-0.1.0-py3-none-any.whl.
File metadata
- Download URL: minenv-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7079f5903a93f3351e851e4a34dd666c626e7f41f8717783fdc4d0af81cd012
|
|
| MD5 |
a4520b114b06042fd3784fd6b6afb839
|
|
| BLAKE2b-256 |
678247034b5edc0bff509e1ed1370bedc9915adc779eca93ce2fe12685d0a8b6
|