Skip to main content

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 successful
  • rc: int - Return code (typically HTTP-style codes like 200, 404, etc.)
  • msg: str - Human-readable message
  • obj: 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 in
  • k: 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 default if not found

Raises:

  • ValueError - If delimiter is not a non-empty string
  • KeyError - If key path doesn't exist and no default is provided

Documentation

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

https://github.com/DrackThor/dracklib

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dracklib-0.0.1.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dracklib-0.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file dracklib-0.0.1.tar.gz.

File metadata

  • Download URL: dracklib-0.0.1.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for dracklib-0.0.1.tar.gz
Algorithm Hash digest
SHA256 02dcf7980ab56a557a3c6141845702008b2c8fda53694f962810936a4728751e
MD5 5bba8e729a716fbc88ee39e1c0bfb532
BLAKE2b-256 1aad22895940137b45d635d44e356a55f9f50ea2a40d8356e6f460a30ac9024d

See more details on using hashes here.

File details

Details for the file dracklib-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: dracklib-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for dracklib-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a28998184e635171b0ebd5fd39b8d4f8eb2ddb85fd558a2af532859309d136a2
MD5 bb2b7383f06486e2ebb8065b377f7089
BLAKE2b-256 34794a4f2a0fe51d9f1ec430e79a1acb2acb684f9dba2bc97f946b07bbc6b2da

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page