python-dotjson
Installation
Sample usage:
pip install dotjson
Introduction
If you want your application to derive configuration using a json file, To help you with that, you can add python-dotjson to your application to make it load the configuration from a settings.json file when it is present (e.g. in development) while remaining configurable via the environment variables.
Sample usage:
from dotjson import load_dotjson()
load_dotjson()
Features
- Sets config vars to env vars
- Support for multiple settings.json files
- Lets you deserialize settings.json file to a Pydantic Model or Dictionary
- Auto picks the settings.json file from root directory
- Ability to load settings from stream
load_dotjson
This method lets you flatten and load the settings.json file to env vars.
Load Env Vars from default settings.json
load_dotjson()
Load Env Vars using json path override
load_dotjson(json_path="settings/settings.dev.json")
Load Env Vars using stream
settings_content = '{"apple":1,"mango":5,"fruit":{"units":["kg","pound"]}}'
load_dotjson(stream=StringIO(settings_content))
Load Env Vars using multiple json paths
settings_paths = ["settings.json", "settings.dev.json"]
load_dotjson(json_paths_list=settings_paths)
dict_dotjson
This method lets you load a dictionary using the settings.json file.
Load dictionary from default settings.json
dict_output = dict_dotjson()
Load dictionary using json path override
dict_output = dict_dotjson(json_path="settings/settings.dev.json")
Load dictionary using stream
settings_content = '{"apple":1,"mango":5,"fruit":{"units":["kg","pound"]}}'
dict_output = dict_dotjson(stream=StringIO(settings_content))
Load dictionary using multiple json paths
settings_paths = ["settings.json", "settings.dev.json"]
dict_output = dict_dotjson(json_paths_list=settings_paths)
model_dotjson
This method lets you load a pydantic model using the settings.json file.
Load dictionary from default settings.json
class fruit_model(BaseModel):
units: List[str]
class settings_model(BaseModel):
apple: int
mango: int
fruit: fruit_model
model_output = model_dotjson(settings_model)
Load dictionary using json path override
class fruit_model(BaseModel):
units: List[str]
class settings_model(BaseModel):
apple: int
mango: int
fruit: fruit_model
model_output = model_dotjson(settings_model, json_path="settings/settings.dev.json")
Load dictionary using stream
class fruit_model(BaseModel):
units: List[str]
class settings_model(BaseModel):
apple: int
mango: int
fruit: fruit_model
settings_content = '{"apple":1,"mango":5,"fruit":{"units":["kg","pound"]}}'
model_output = model_dotjson(settings_model, stream=StringIO(settings_content))
Load dictionary using multiple json paths
class fruit_model(BaseModel):
units: List[str]
class settings_model(BaseModel):
apple: int
mango: int
fruit: fruit_model
settings_paths = ["settings.json", "settings.dev.json"]
model_output = model_dotjson(settings_model, json_paths_list=settings_paths)
Inspired by
- python-dotjson: https://github.com/theskumar/python-dotenv
References
- poetry: https://github.com/python-poetry/poetry
- gitversion: https://github.com/GitTools/GitVersion
- Pydantic: https://github.com/samuelcolvin/pydantic
Metadata
Release files for dotjson 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 | Actions |
|---|---|---|---|---|
| dotjson-0.1.2.tar.gz | 3.5 kB | Without provenance | Details for dotjson-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dotjson-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for dotjson-0.1.2-py3-none-any.whl |
Total release size: 6.7 kB
Release files / dotjson-0.1.2.tar.gz
| Download URL | dotjson-0.1.2.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6afb853208c988c37f03175951c4ef954f961863085cdb88a0cb8c57491c9fc3
|
|
BLAKE2b-256 checksum How to use checksums |
3629490d68d3b96df73fbf4110be4a456fc0a91ae483c84e0a3a70922e1bf691
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.8.13 Linux/5.13.0-1025-azure
|
Release files / dotjson-0.1.2-py3-none-any.whl
| Download URL | dotjson-0.1.2-py3-none-any.whl |
|---|---|
| Size | 3.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6680fed6922a83128e668a1f4bf34b3aed2545c11eab3d4c939456c427cadb82
|
|
BLAKE2b-256 checksum How to use checksums |
aa471f1b230833283d0ea71ea6df0aa1b228d0edd911dd25f42c45fe102c57a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.8.13 Linux/5.13.0-1025-azure
|
Security for dotjson 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.