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]]

✨ Features

  • ✅ Precise type hint inference for dynamic values
  • 🔁 Supports nested containers (e.g., List[Dict[str, Tuple[int, float]]])
  • 🧠 Handles heterogeneous collections using Union[...]
  • 🧹 Compatible with third-party objects (like torch.Tensor, np.ndarray, ...)
  • ⚙️ Extensible and easy to integrate in tooling, type-checking, or docs

📚 Examples

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

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

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

infer_type((1, "hello", 3.5))
# Tuple[int, str, float]

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

infer_type([torch.tensor(1), torch.tensor(2)])
# List[torch.Tensor]

🛠 Use Cases

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

🔮 Roadmap

  • CLI support (e.g., typepeek file.json)
  • String output mode (as_str=True)
  • Support for Optional, TypedDict, NamedTuple, etc.
  • Type alias simplifier for long Union[...] types
  • JSON Schema export

🙌 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.1.0.tar.gz (4.1 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.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for typepeek-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c041afa18433277a853c4aa353f3e61648955396f492f0e49a02065b256d815f
MD5 8fe2498b847678358506c68160dcf6ad
BLAKE2b-256 673d988480709cf403f04efe12aabfa2a578a415c5092a45e95bd00463bb36a4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: typepeek-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f934cae8a3ad4b86225f3e5d1d94f5100125e9a4220f860de4701d883e1965a9
MD5 5a2aa389eaa41773ecd63bd55010adeb
BLAKE2b-256 720c969f1f13158dc46a82c4baa8a9c5665f5bd376dd749d3b756c51349741be

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