Totally typed, plausibly practical, and remarkably random utilities—for me, and maybe for you too.
Project description
Totally typed, plausibly practical, and remarkably random utilities—for me, and maybe for you too.
Documentation: https://Kajiih.github.io/kajihs-utils/
Source Code: https://github.com/Kajiih/kajihs-utils
🧰 Kajih's Utils
⬇️ Installation
We recommend you use uv to install packages from PyPI:
uv add kajihs-utils
🧩 Example
# Useful protocols for structural subtyping
from kajihs_utils.protocols import SupportsAllComparisons, SupportsDunderLT
x: SupportsAllComparisons[int]
# === Core Algorithm Features ===
from kajihs_utils import get_first, is_sorted
# Get first key existing in a dict
d = {"a": 1, "b": 2, "c": 3}
print(get_first(d, ["x", "a", "b"])) # Output: 1
# Check if an iterable is sorted
print(is_sorted([1, 2, 2, 3])) # Output: True
print(is_sorted("cba", reverse=True)) # Output: True
print(is_sorted([0, 1, 0])) # Output: False
from kajihs_utils.core import bisect_predicate
# Find partition points in sorted data
numbers = [1, 3, 5, 7, 9]
first_big = bisect_predicate(numbers, lambda x: x < 6)
print(f"First number >= 6 is at index {first_big}") # Output: First number >= 6 is at index 3
# Works with custom objects and complex predicates
records = [
{"temp": 12, "rain": 0.1},
{"temp": 15, "rain": 0.3},
{"temp": 18, "rain": 0.0}, # First "nice" day: temp >15 AND rain <0.2
{"temp": 20, "rain": 0.1},
]
nice_day_idx = bisect_predicate(records, lambda day: not (day["temp"] > 15 and day["rain"] < 0.2))
print(f"First nice day at index {nice_day_idx}") # Output: First nice day at index 2
# === Loguru features ===
from kajihs_utils.loguru import prompt, setup_logging
# Better logged and formatted prompts
prompt("Enter a number")
# Simply setup well formatted logging in files and console
setup_logging(prefix="app", log_dir="logs")
# === Numpy features ===
import numpy as np
from kajihs_utils.numpy_utils import Vec2d, find_closest
x = np.array([[0, 0], [10, 10], [20, 20]])
print(find_closest(x, [[-1, 2], [15, 12]])) # Output: [0 1]
# Vec2d class
v = Vec2d(3.0, 4.0)
print(v) # Output: [3. 4.]
print(tuple(v)) # Output: (np.float64(3.0), np.float64(4.0))
print(v.x) # Output: 3.0
print(v.y) # Output: 4.0
print(v.magnitude()) # Output: 5.0
print(v.normalized()) # Output: [0.6 0.8]
print(v.angle()) # Output: 53.13010235415598
print(v.rotate(90, center=(1, 1))) # Output: [-2. 3.]
# === Whenever features ===
from datetime import datetime
from kajihs_utils.whenever import AllDateTime, ExactDateTime, dt_to_system_datetime # Useful types
print(dt_to_system_datetime(datetime.now())) # Output: 2025-05-01T09:48:13.348903+00:00
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
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 kajihs_utils-0.10.2.tar.gz.
File metadata
- Download URL: kajihs_utils-0.10.2.tar.gz
- Upload date:
- Size: 88.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45a2e2ba1160276b5326130847e45d8fecd8364bf7291786f0a1d4040cae90f5
|
|
| MD5 |
6ba656afa7e376ddb065dd90014def97
|
|
| BLAKE2b-256 |
f634532abb5d486ed3d76b70c1a1dbdbdd00cb8d66ae42bb09b43482eaf30f80
|
Provenance
The following attestation bundles were made for kajihs_utils-0.10.2.tar.gz:
Publisher:
publish.yaml on Kajiih/kajihs-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kajihs_utils-0.10.2.tar.gz -
Subject digest:
45a2e2ba1160276b5326130847e45d8fecd8364bf7291786f0a1d4040cae90f5 - Sigstore transparency entry: 260518204
- Sigstore integration time:
-
Permalink:
Kajiih/kajihs-utils@2685264759d8ca332dfe8847280e959b01bafd49 -
Branch / Tag:
refs/tags/0.10.2 - Owner: https://github.com/Kajiih
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@2685264759d8ca332dfe8847280e959b01bafd49 -
Trigger Event:
push
-
Statement type:
File details
Details for the file kajihs_utils-0.10.2-py3-none-any.whl.
File metadata
- Download URL: kajihs_utils-0.10.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
252b80db503149e0f148e8431c372f68e54bff0debaf06ec53dd6e1a3d681594
|
|
| MD5 |
cf810c18b470b0c48c23f7f753d23cdd
|
|
| BLAKE2b-256 |
6fbe02e19fc2c148b31baa79f0d6568ddd7c37c287f2985cfc19f9096de10aa0
|
Provenance
The following attestation bundles were made for kajihs_utils-0.10.2-py3-none-any.whl:
Publisher:
publish.yaml on Kajiih/kajihs-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kajihs_utils-0.10.2-py3-none-any.whl -
Subject digest:
252b80db503149e0f148e8431c372f68e54bff0debaf06ec53dd6e1a3d681594 - Sigstore transparency entry: 260518213
- Sigstore integration time:
-
Permalink:
Kajiih/kajihs-utils@2685264759d8ca332dfe8847280e959b01bafd49 -
Branch / Tag:
refs/tags/0.10.2 - Owner: https://github.com/Kajiih
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@2685264759d8ca332dfe8847280e959b01bafd49 -
Trigger Event:
push
-
Statement type: