Skip to main content

typed-env

A python module that help you have a type safety on enviroment variable (on runtime)

Documentation

timelessnesses.TypedEnv

A parent class that will help you ensure type safetiness on your enviroment variable.
Usage:

from timelessnesses import typed_env
import datetime

class MyDotEnv(typed_env.TypedEnv):
    # define your enviroment variable name and it's type (default value is optional and typing.Optional is also supported)
    AMONG_US: bool = True
    DISCORD_TOKEN: str
    DATETIME: datetime.datetime = datetime.datetime.now()
    NICE_DICTIONARY: typing.Dict[str, int] = {"a": 1, "b": 2}
    DAMN_LIST: typing.List[int] = [1, 2, 3]
    BALLS_KIND: BallsEnum # oh no! TypedEnv doesn't support my custom class!
    # don't worry you can implement your own converter!

a = MyDotEnv()
a.add_validator(BallsEnum, lambda x: BallsEnum(int(x)))
a.configure(typed_env.Method.dotenv, dotenv=".env") # you have options to either get only from dotenv or os.environ or both!
"""
a.get_env(typed_env.Method.all, dotenv="path_to_.env") # this fetch all the variable from both dotenv and os.environ
a.get_env(typed_env.Method.env) # this fetch all the variable from os.environ
a.get_env(typed_env.Method.dotenv, dotenv="path_to_.env") # this fetch all the variable from dotenv
NOTE: for dotenv/all method you have to supply dotenv argument
"""
a.raise_error_on_unknown_env = False # if this set to true any excessive enviroment variable will raise an error (default is True)
a.load() # let it do the work!

TypedEnv supports normal types like str or int and also typing.Dict and typing.List etc. But it also supports custom type by adding a validator, you are also allowed to overwrite the default validator by using TypedEnv.add_validator method.
Check out more examples at tests folder!

Metadata

Release files for timelessnesses-typed-env 1.0.3

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

Source distribution (sdist)

Source distribution for timelessnesses-typed-env 1.0.3
File Size Uploaded
timelessnesses_typed_env-1.0.3.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for timelessnesses-typed-env 1.0.3
File Interpreter ABI Platform
timelessnesses_typed_env-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / timelessnesses_typed_env-1.0.3.tar.gz

Download URL timelessnesses_typed_env-1.0.3.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
962c53dc4343f8c0122e3162df7f5669fc6973fa73c5717bd1eed1fd2be08c76
BLAKE2b-256 checksum
How to use checksums
312b57b1ca46a069c38264ad9a10cf5abdacdd8d4445f7068aa0256a8ddc28f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.0

Release files / timelessnesses_typed_env-1.0.3-py3-none-any.whl

Download URL timelessnesses_typed_env-1.0.3-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3994e8a33a9db6cbc1d0324dcbfcaa4f5e7260924f312119822ec6c77bf40b9f
BLAKE2b-256 checksum
How to use checksums
282b70e73a545bdd94e15381948a35277b60350b86e46a8eccf64dce445ad642
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.0

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.0

2 release files

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