Skip to main content

Personal Python utility library — decorators, helpers, classes, and utils.

Project description

jsi-tools

CI PyPI Python License: GPL v3

Personal Python utility library — decorators, helpers, classes, and utils.

Installation

pip install jsi-tools

Decorators

@log_return

Logs the return value of a function with type and size information. Zero side effects — the return value is never modified.

import logging
from jsi_tools import log_return

@log_return
def get_users():
    return ["alice", "bob", "charlie"]

get_users()
# DEBUG — get_users returned list[len=3]: ['alice', 'bob', 'charlie']

Works with or without arguments:

@log_return(level=logging.INFO, max_length=50)
def fetch_config():
    return {"host": "localhost", "port": 8080, "debug": True}

fetch_config()
# INFO — fetch_config returned dict[len=3]: {'host': 'localhost', 'port': 8080, ...

Parameters:

Parameter Type Default Description
level int logging.DEBUG Log level
logger Logger | None None Custom logger (defaults to function's module logger)
max_length int | None None Truncate repr output

Supports: sync functions, async functions, generators, instance/static/class methods, all Python types.

Log format: {qualname} returned {type}[len={n}]: {repr}

Type info examples:

Return value Type info
42 int
"hello" str[len=5]
[1, 2, 3] list[len=3]
{"a": 1} dict[len=1]
None None
(generator) generator

Helpers

diff

Computes a structured diff between two collections of the same type. Supports lists, sets, frozensets, and dicts. Returns an immutable result object.

from jsi_tools import diff

# Lists — multiset semantics
result = diff([1, 2, 2, 3], [2, 3, 4, 4])
result.added    # (4, 4)
result.removed  # (1, 2)
result.common   # (2, 3)

# Sets
result = diff({"a", "b", "c"}, {"b", "c", "d"})
result.added    # frozenset({"d"})
result.removed  # frozenset({"a"})
result.common   # frozenset({"b", "c"})

# Dicts — tracks added, removed, changed, and unchanged keys
result = diff({"a": 1, "b": 2, "c": 3}, {"b": 20, "c": 3, "d": 4})
result.added     # {"d": 4}
result.removed   # {"a": 1}
result.changed   # {"b": (2, 20)}
result.unchanged # {"c": 3}

Return types:

Input type Return type Fields
list ListDiff[T] added, removed, common (tuples)
set / frozenset SetDiff[T] added, removed, common (frozensets)
dict DictDiff[KT, VT] added, removed, changed, unchanged (read-only mappings)

All results are immutable (frozen dataclasses with immutable field types).

Raises TypeError if types differ, are unsupported, or are tuples (with a hint to convert to list).

Development

git clone https://github.com/sdejongh/jsi-tools.git
cd jsi-tools
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest tests/ -v       # tests
ruff check src/ tests/ # lint
mypy src/              # type check

License

GPL-3.0

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

jsi_tools-0.2.0.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

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

jsi_tools-0.2.0-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file jsi_tools-0.2.0.tar.gz.

File metadata

  • Download URL: jsi_tools-0.2.0.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jsi_tools-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cb253960643b653a3065b3266486cb1b420a0c8e6f63f30a6886dd80de2c2a9d
MD5 65e0706b53eefecc277c2d26d50eca3d
BLAKE2b-256 af20f301e339c616ac522477c15555c139b3e42fd3e129004657ee02ddb45ffe

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsi_tools-0.2.0.tar.gz:

Publisher: release.yml on sdejongh/jsi-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jsi_tools-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: jsi_tools-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jsi_tools-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 467eaaf72748e16c61080687dcb3f2b003901f45f6e3ec4e74a9ebe9ce544017
MD5 b3e0ce9ed2cd1cba8399701c20924979
BLAKE2b-256 9244497c7d64a8eacba69f69ac2ea155d72f5d50c376482e6e2b7294ddbe62a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsi_tools-0.2.0-py3-none-any.whl:

Publisher: release.yml on sdejongh/jsi-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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