bindr
Bind dictionary data into named tuples and dataclasses automatically for typed attribute access throughout the rest of your codebase.
from bindr import bind
from typing import Dict, List, NamedTuple
from yaml import safe_load
class Config(NamedTuple):
class SMSServiceConfig(NamedTuple):
host: str
port: int
username: str
password: str
class S3Config(NamedTuple):
default_bucket: str
default_region: str
max_item_size: int
support_emails: List[str]
api_key: str
timeout_ms: int
pi: float
sms_providers: List[SMSServiceConfig]
s3_settings: S3Config
accounts: Dict[str, str]
config = bind(Config, safe_load("config.yaml"))
config.s3_settings.max_item_size # <-- int
Installation
Bindr is developed on GitHub and hosted on PyPI. You can fetch Bindr using a simple:
pip install bindr
Why does this exist?
Bindr is not meant to serve as a replacement for 12Factor methodology. There are certain niche cases where you might want to read in a structured file (such as JSON or YAML) and bind it directly to a typed object outside of application configuration (as demonstrated in the example above). In fact, application configuration created as a dictionary (perhaps from environment variables) is still a valid use case for a bound object.
Bindr exists as an alternative to the automatic binding syntax offered by PyYAML. The default object deserialization syntax in PyYAML is a leaky abstraction. Declarative data formats such as YAML should not be concerned with the details of how objects are deserialized in your application code.
Objects generated via Bindr will give you typed objects that can be passed around and verified by MyPy and hinted in PyCharm, which is a distinct advantage over accessing multiple levels deep of nested dictionaries.
License
MIT License
Metadata
Release files for bindr 0.1.1
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 |
|---|---|---|---|---|
| bindr-0.1.1.tar.gz | 5.3 kB | Without provenance | Details for bindr-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bindr-0.1.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for bindr-0.1.1-py2.py3-none-any.whl |
Total release size: 10.5 kB
Release files / bindr-0.1.1.tar.gz
| Download URL | bindr-0.1.1.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56fa0a9147c41414df869388040c285ee77fc9ec810b1aae43f1d455bd41f5fa
|
|
BLAKE2b-256 checksum How to use checksums |
27cd64b4baa29484cc173740e9f4c8a4d53bd3c38a23f56c42ccb70830cf33ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
|
Release files / bindr-0.1.1-py2.py3-none-any.whl
| Download URL | bindr-0.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
73b57e43321d7321a0ef69cc817c67b7f06bd7d6c5b8c2465eacaea97fe33fc6
|
|
BLAKE2b-256 checksum How to use checksums |
9dac9ea4ae1f6f193470f614a2c34172daebcebc0a2e069b3d9ec432465e623f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
|
Security for bindr 0.1.1
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.