Registry / type-stubs / useful-types

useful-types

JSON →
library0.2.1pypypiunverified

useful-types is a Python library offering a collection of common type aliases and protocols to reduce boilerplate in projects. It aims to provide frequently used type definitions, such as JSON-related types. The library's types are not specially handled by type checkers, and users are encouraged to vendor them if they wish to avoid a direct dependency. It is currently at version 0.2.1 and maintains an active development cadence with occasional updates to type definitions.

pip install useful-types
INSTALL
IMPORT
SIG · USEFUL-TYPES
U
useful-types
type-stubspythonv0.2.1
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JSONDict
from useful_types import JSONDict
from useful_types import JSONDict

This quickstart demonstrates the use of `JSONDict` and `JSONType` to define and process data conforming to JSON structures. It shows how to type-hint complex nested JSON data and perform basic operations while maintaining type safety.

from useful_types import JSONDict, JSONType def process_json_data(data: JSONType) -> JSONType: if isinstance(data, dict): if 'id' in data and isinstance(data['id'], str): print(f"Processing record with ID: {data['id']}") return {k: v for k, v in data.items() if k != 'private_field'} elif isinstance(data, list): return [process_json_data(item) for item in data] return data example_dict: JSONDict = { "name": "Alice", "age": 30, "isStudent": False, "courses": ["Math", "Science"], "address": {"street": "123 Main St", "zip": 90210}, "private_field": "secret" } example_list: JSONType = [1, "hello", True, None, example_dict] processed_data = process_json_data(example_list) print(f"Original: {example_list}") print(f"Processed: {processed_data}")
Debug
Known issues
gotchaThe library explicitly states that its types are not specially handled by type checkers and encourages users to 'vendor' (copy) them into their own projects if they prefer not to take on a direct dependency. This is a design philosophy choice, not a technical limitation.
fix
Consider whether you want to include 'useful-types' as a dependency or copy the specific type definitions you need directly into your codebase, as recommended by the library author. Either approach is supported.
affects: All versions
gotchaThe library guarantees support on `mypy 1.4` and `pyright 1.1.314` or higher. Using older versions of these type checkers or alternative type checkers (e.g., Pyright, Pylance, etc.) might lead to unexpected type-checking behavior or errors, as the types might rely on newer type checker features.
fix
Ensure your project's type checker (mypy or pyright) meets or exceeds the stated minimum versions. If using another type checker, verify compatibility by running your type checks against the library's types.
affects: <=0.2.1
Upgrade
Version history
0.2.1latest on PyPI · released Apr 20, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
47 hits · last 30 days
node
40
OpenAI (training)
1
Resources
useful-types — pip install useful-types · libregistry