I don't like multi-line dictionaries. They're ugly, take up too much space, and distract me from the real logic in the code. I could put it all on one line but then that would break line length convention and be unreadable. In most dictionaries only a few values vary and the rest are constants you type once. This package moves those values into a template you declare once, leaving the call site with just what changes. Nothing crazy, just a small OCD annoyance solved.
Usage
from packd import packd, template
@template
def conn(host: str, port: int, *, timeout: int = 30, ssl: bool = True): ...
packd("conn", "localhost", 5432)
# {"host": "localhost", "port": 5432, "timeout": 30, "ssl": True}
Parameters before the asterisk are passed in, matched by position. Keyword parameters are filled from their defaults, and can be overriden per call.ridden per call:
packd("conn", "localhost", 5432, timeout=5)
Output Keys
Sometimes you need to alias the keys in your dictionary, so you can either convert
them to a case found in the CaseEnum class or alias them individually. You can
do both, the alias always wins.
from packd import CaseEnum
@template(case=CaseEnum.CAMEL, aliases={"content_type": "Content-Type"})
def headers(token: str, *, content_type: str = "application/json", read_timeout: int = 30): ...
packd("headers", "supersecrettoken")
# {"token": "abc", "Content-Type": "application/json", "readTimeout": 30}
Quick Note
The templates register on import, so a template in a file nothing imports won't be found.
Metadata
Release files for packd 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| packd-0.1.0.tar.gz | 52.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| packd-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 56.4 kB
Release files / packd-0.1.0.tar.gz
| Download URL | packd-0.1.0.tar.gz |
|---|---|
| Size | 52.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d2fd53f4f64b7f2067a40951c51607e232154f1bb371f3823d12903e5cf229d
|
|
BLAKE2b-256 checksum How to use checksums |
58469cf1f4e2487706dfa65619cb4b8e829c0e3e3270faf8dde071affd6781e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / packd-0.1.0-py3-none-any.whl
| Download URL | packd-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
19730b9c4d239ad9cb97ba1b0f26de995a68342215ba9dc3c6978ffe1934f211
|
|
BLAKE2b-256 checksum How to use checksums |
a3d8ec5ebf8cca14e341995cd25cca550bd805a73e9421fcf77dc603281c130c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|