My collection of useful Python stuff.
Project description
dracklib
My collection of useful Python stuff.
Installation
pip install dracklib
# or with uv:
uv add dracklib
See installation.md for more details on setting up uv and Python.
API Reference
RC - Return Code Dataclass
A simple dataclass for structured function returns containing status information.
from dracklib import RC
res = RC(ok=True, rc=0, msg="Success", obj=None)
Fields:
ok: bool- Whether the operation was successfulrc: int- Return code (typically HTTP-style codes like 200, 404, etc.)msg: str- Human-readable messageobj: Any- Optional object containing result data
Usage Example:
from dummy import load_data
from dracklib import RC
def fetch_data() -> RC:
try:
data = load_data()
return RC(ok=True, rc=200, msg="Data loaded", obj=data)
except Exception as e:
return RC(ok=False, rc=500, msg=str(e), obj=None)
result = fetch_data()
if result.ok:
print(f"Success: {result.obj}")
else:
print(f"Error {result.rc}: {result.msg}")
dget - Dictionary Nested Value Retrieval
Retrieve values from nested dictionaries using a delimiter-separated key string.
from dracklib import dget
data = {'user': {'name': 'John', 'address': {'city': 'New York', 'zip': '10001'}}}
# Get nested value
city = dget(data, 'user.address.city') # Returns 'New York'
# Use custom delimiter
data2 = {'a/b/c': 'value'}
result = dget(data2, 'a/b/c', delimiter='/')
# With default value
missing = dget(data, 'user.phone', default='N/A') # Returns 'N/A'
Parameters:
d: dict- The dictionary to search ink: str- Delimiter-separated key path (e.g.,'user.address.city')delimiter: str- Key separator (default:'.')default: Any- Value to return if key not found (default:None)
Returns:
- The value at the specified path, or
defaultif not found
Raises:
ValueError- If delimiter is not a non-empty stringKeyError- If key path doesn't exist and no default is provided
Documentation
- installation.md - Installing uv and Python
- development.md - Development setup and workflows
- publishing.md - Publishing releases to PyPI
Development
See development.md for detailed development instructions.
Quick start:
# install dependencies
make install
# run linting and tests
make
# run tests individually
uv run pytest
License
MIT License - see LICENSE for details.
Author
Daniel Drack (daniel@drackthor.me)
Repository
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dracklib-0.0.2.tar.gz.
File metadata
- Download URL: dracklib-0.0.2.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a130f731d8cb85f66785dbca3a7bdf88eccee0bc56b0bd90a5748695456560c7
|
|
| MD5 |
b1033f7e64d9da1188089652d297f893
|
|
| BLAKE2b-256 |
d2ac54990a15d5a77dbd8a24f91b69fd733086196f39d33ed373772556a0499e
|
File details
Details for the file dracklib-0.0.2-py3-none-any.whl.
File metadata
- Download URL: dracklib-0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d354d6b0d1729553c6088ac95b8cf25e8eb9f2b3618cc02250c629efb3bad233
|
|
| MD5 |
cde60c3924b08b54efb6a5a7614bd06d
|
|
| BLAKE2b-256 |
bd41315a63b758c0378821804e855fc1cbb4dd749d0a8a46bf686eda838f7982
|