A python module that help you have a type safety on enviroment variable
Project description
typed-env
A python module that help you have a type safety on enviroment variable
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.get_env(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!
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 timelessnesses_typed_env-1.0.1.tar.gz
.
File metadata
- Download URL: timelessnesses_typed_env-1.0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.9 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb1438d3cf77084ca74469897fb106ffb2211d1f3c6984c8df1027d843f46772 |
|
MD5 | 953f931fdc53f88303c21d11f4b12cd5 |
|
BLAKE2b-256 | d9f22cf625510b038e6a5e4957c24f2168276e901553e9355bfbba3c46473bde |
File details
Details for the file timelessnesses_typed_env-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: timelessnesses_typed_env-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.9 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 531da84090bb8324aa4debd37395b1e14245746f6e9c643edc0014c92ebad4ca |
|
MD5 | de3a55470cf2ccc2819c8887aab99c70 |
|
BLAKE2b-256 | d9517488745c970f3b476c603ffb21e21d8a5ecb7d5e1e9b8c037e9d8b474d15 |