magicenv
Simple way to parse common datatypes from env vars.
Setup
pip install magicenv
Usage
from magicenv import env
DB_HOST = env('DB_HOST', "localhost:1234") # string var
DB_NUM_TRANSACTIONS = env('DB_NUM_TRANSACTIONS', 1234) # int var
ENABLE_FEATURE_X = env('ENABLE_FEATURE_X', True) # bool var
DB_SERVERS = env('DB_SERVERS', ['server1', "server2"]) # interprets a comma separated string as a list
env()
def env(key, default=None, return_type=None, list_element_type=str):
| Param | Explanation |
|---|---|
| key | name of environment variable. |
| default | Optional - default value if key is not present in environment |
| return_type | Optional - specify return_type. |
| list_element_type | Optional - cast/parse each element of a list with provided callable. Only used if the setting is a list. |
If key is not present in environment, and there is not provided a default value, None will be returned.
Guidelines for settings in Environment
A couple of conventions exist when designing environment variables for settings.
-
All values are stored as strings in the environment variable
-
Booleans All boolean variables are encoded as one of "1", "True" or "true" if True, all other values are interpreted as False
-
Lists are encoded as a comma separated string in example: "a,b,c, d" (intentionally put whitespace in there. It is allowed)
-
Default Values are preffered to be set to the same type as the setting.
The type of the default value implicitly sets the datatype of the env var.
May be overriden by setting return_type explicitly.
list->[],str->''int->0bool->TrueorFalse
Metadata
Release files for magicenv 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| magicenv-0.1.2.tar.gz | 3.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| magicenv-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.5 kB
Release files / magicenv-0.1.2.tar.gz
| Download URL | magicenv-0.1.2.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dec834b73c6f08160e96c26595f95251ed28bb6d392ed46a19b7bc419508cbaf
|
|
BLAKE2b-256 checksum How to use checksums |
94da6859f79770648dc1567f4e7d11bdaa310b36c7236019e0e9f5d0586261e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.7.10 Darwin/19.6.0
|
Release files / magicenv-0.1.2-py3-none-any.whl
| Download URL | magicenv-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6392f9bcfcb1a26318219b1543467d6ed6c71f6205e33007e45177ba0063bf8d
|
|
BLAKE2b-256 checksum How to use checksums |
6cc81616b024c4d310cedcae86a4b7c65c0fbfa45b575a9eb7a8eee995c58740
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.7.10 Darwin/19.6.0
|
Security for magicenv 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.