Skip to main content

Infer type hints from runtime Python data

Project description

📦 typepeek

typepeek is a lightweight Python package that infers accurate, human-readable type hints from runtime data — including nested and complex containers like lists, dictionaries, tuples, sets, and even third-party objects like PyTorch tensors.


🚀 Quick Start

Installation

pip install typepeek

Example Usage

from typepeek import infer_type
import torch

data = [torch.tensor(1), torch.tensor(2), 3]
print(infer_type(data))
# Output: List[Union[torch.Tensor, int]]
print(infer_type(data, agnostic=False))
#typing.List[torch.Tensor, torch.Tensor, int]

✨ Features

  • Precise Type Inference — Accurately infers human-readable type hints from runtime values
  • 🔁 Deep Nested Structure Support — Handles arbitrarily nested containers (e.g., List[Dict[str, Tuple[int, float]]])
  • 🧹 Third-Party Object Compatibility — Understands common libraries like torch.Tensor, np.ndarray, and more
  • 🔄 Ordered and Unordered Type Support — Handles both ordered collections (e.g., List[int, float, str, int]) and unordered collections (e.g., List[Union[int, float, str]]).

📚 Examples

infer_type([1, 2, 3])
# typing.List[int]

infer_type(["a", 1, 3.14])
# typing.List[typing.Union[str, int, float]]

infer_type({"name": "Alice", "age": 30})
# typing.Dict[str, Union[str, int]]

infer_type((1, "hello", 3.5), agnostic=False)
#typing.Tuple[int, str, float]

infer_type([[1, 2], [3, 4]])
# typing.List[typing.List[int]]

infer_type([torch.tensor(1), np.array(2)], agnostic=False)
#typing.List[torch.Tensor, numpy.ndarray]

🛠 Use Cases

  • 📦 Auto-generate type hints for untyped or runtime-generated data
  • 🧪 Write better tests for dynamic outputs
  • 🧠 Debug and inspect complex runtime object structures

🙌 Contributing

Contributions are welcome! If you have an idea, bug, or feature request, feel free to open an issue or submit a pull request.


📄 License

This project is licensed under the MIT License. See the LICENSE file for details.


👤 Author

👨‍💻 Le Hoang Viet
🐙 GitHub: Mikyx-1

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

typepeek-0.2.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

typepeek-0.2.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: typepeek-0.2.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for typepeek-0.2.0.tar.gz
Algorithm Hash digest
SHA256 120509e7c81c776bc65c3b8d7f9037476154cb5fe7255fcfaf9de8d21ae61ac7
MD5 bda194bca6b4ed916bd7bd164fa2ac43
BLAKE2b-256 647a0dc6736f4e9e2dae37a5600a765565f5e9b2759443ea7ea1066d0a124c94

See more details on using hashes here.

File details

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

File metadata

  • Download URL: typepeek-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for typepeek-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6690a900c30cdd88334875f2bc6ab895ca1da6f45014b4cf72b1695a08e11cc8
MD5 5b9e74305d67a559d2d28ddf62fef746
BLAKE2b-256 a140cdc0f1060264ef98da27561c9657c4a9239d5da0d63324e88409118d19f2

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