cattrs-env
cattrs-env is an Environment Variable parser/validator which utilizes the cattrs library.
cattrs-env parses Environment Variables from os.environ and structures them into a cattrs compatible dataclass. Providing you with easy and type safe environment variables in your project.
Because cattrs-env gets the Environment Variables from os.environ, it is fully compatible with any Environment Variable loading library such as python-dotenv.
from dataclasses import dataclass
from typing import List, Optional
from cattrs_env import CattrsEnv
@dataclass
class Env(CattrsEnv):
A: int
C: List[str]
B: Optional[float] = None
env = Env.load()
env.A
env.C
env.B
Examples
dataclass example
import os
from dataclasses import dataclass
from typing import List, Optional
from cattrs_env import CattrsEnv
@dataclass
class Env(CattrsEnv):
A: int
C: List[str]
B: Optional[float] = None
if __name__ == "__main__":
os.environ.update(
{
"A": "99",
"B": "9.9",
"C": '["a","b","c", 1]',
}
)
env = Env.load()
print(env)
attrs example
import os
from typing import List, Optional
import attrs
from cattrs_env import CattrsEnv
@attrs.define
class Config:
E: str
F: Optional[int] = None
@attrs.define
class Env(CattrsEnv):
A: int
C: List[str]
D: Config
B: Optional[float] = None
if __name__ == "__main__":
os.environ.update(
{
"A": "99",
"B": "9.9",
"C": '["a","b","c", 1]',
"D": """{'E':"abcdef"}""",
}
)
env = Env.load()
python-dotenv example
from dataclasses import dataclass
from typing import List, Optional
import dotenv
from cattrs_env import CattrsEnv
@dataclass
class Env(CattrsEnv):
A: int
C: List[str]
B: Optional[float] = None
ENV_FILE_CONTENTS = """
A=1
B=99.9
C="['foo', 'bar']"
"""
if __name__ == "__main__":
with open(".env", "w") as env_file:
env_file.write(ENV_FILE_CONTENTS)
dotenv.load_dotenv()
env = Env.load()
print(env)
Metadata
Release files for cattrs-env 1.0.4
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 | Actions |
|---|---|---|---|---|
| cattrs-env-1.0.4.tar.gz | 4.0 kB | Without provenance | Details for cattrs-env-1.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cattrs_env-1.0.4-py3-none-any.whl | Python 3 | none | any | Details for cattrs_env-1.0.4-py3-none-any.whl |
Total release size: 7.9 kB
Release files / cattrs-env-1.0.4.tar.gz
| Download URL | cattrs-env-1.0.4.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
518106ae678d697e759a03db630296232e6134fc71aaa5ba6932668c5e722c3d
|
|
BLAKE2b-256 checksum How to use checksums |
c7f25cc47839a8dc804da9eebd80b14be66f2f0dfb7ee03a78d6f129066e75c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Release files / cattrs_env-1.0.4-py3-none-any.whl
| Download URL | cattrs_env-1.0.4-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5084d5eae27a6178fec0d7d4c3921a7232d2b3a83d3f046e1ba6917b5ccd60d3
|
|
BLAKE2b-256 checksum How to use checksums |
03bdeb39545f271b32a111b51725995fccdf6140e033fab0a311bcf1ced345e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for cattrs-env 1.0.4
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.