Skip to main content

env-get

Manage and retrieve env variables in Python.

Install

$ pip install env-get

Usage

from env_get import env

port = env('SERVER_PORT', env.integer, 80)

env(key, converter, defaults) -> Any

def Converter(v: Any, key: str, is_default: bool) -> Any:
  • key str: The environment variable key.
  • converter Optional[Converter | List[Converter]] A converter function or a list of converter functions.
    • v the current value of the variable
    • key the key of the environment variable
    • is_default True means the environment variable is not set, even not set as FOO=
  • defaults Opitonal[Any] The optional default value if the environment variable is not found.

Returns Any the retrieved env variable.

Built-in Converter Functions

  • env.boolean: Converts the value to a boolean. Treats 'true', '1', 'Y', 'y', 'yes', and True as True.
  • env.integer: Converts the value to an integer. Returns 0 if conversion fails.
  • env.required: Ensures that the environment variable is set. Raises a EnvRequiredError if not.

Examples

Boolean Conversion

debug_mode = env('DEBUG_MODE', env.boolean, False)

Integer Conversion

port = env('PORT', env.integer, 8080)

Required Variable

from env_get import env, EnvRequiredError

try:
    api_key = env('API_KEY', env.required)
except RangeError as e:
    print(e)  # Output: env "API_KEY" is required

Handling Multiple Converters

You can apply multiple converters by passing a list of converter functions.

value = env('SOME_VAR', [env.required, env.integer], 10)

License

MIT

Metadata

Release files for env-get 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for env-get 1.1.0
File Size Uploaded Provenance
env_get-1.1.0.tar.gz 5.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for env-get 1.1.0
File Interpreter ABI Platform
env_get-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / env_get-1.1.0.tar.gz

Download URL env_get-1.1.0.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7cfcb2a659b3c34ad8cc52194b31b1cbe10ebb27b801d7a6ac3cf0f4d72713fb
BLAKE2b-256 checksum
How to use checksums
a77368ca410cb688e29c823d105545222dd3c74c3b243506a3b3c6e760779397
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.3

Release files / env_get-1.1.0-py3-none-any.whl

Download URL env_get-1.1.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aec5a953065e985564f260139c8d935b63a81a386a628d6a6d958beb439be1d4
BLAKE2b-256 checksum
How to use checksums
0de026c5dc9efb7bfe4d8d2e1d42f4a292c06352dd2f7417e143c116b65c3ca6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.3

Security for env-get 1.1.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page