Python type inference from a stream of data
Project description
slow-learner — python type inference tool
See also: post
A library and CLI to consume a stream of values (for CLI — JSON documents) and generate Python types describing it. Features:
- recursion into mappings and collections with generic types generation
- "structured dicts" are turned into
TypedDict
s by default - values with a small set of observed values are turned into
Literal
s
Installation
pip install slow-learner
Usage
As CLI:
slow-learner learn 1.json 2.json 3.json
# to learn the type of list item
slow-learner learn --spread list.json
In Python:
from slow_learner import TypeLearner
tl = TypeLearner(
max_literal_type_size=5,
learn_typed_dicts=True,
max_typed_dict_size=50,
max_recursive_type_depth=5,
no_literal_patterns=[r"\.password", r".*secret"],
)
for value in my_values:
tl.observe(value)
tl.save_type_definition("result.py", "MyType")
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
slow_learner-0.1.3.tar.gz
(26.6 kB
view details)
Built Distribution
File details
Details for the file slow_learner-0.1.3.tar.gz
.
File metadata
- Download URL: slow_learner-0.1.3.tar.gz
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 263b402b878a150c973a0861a85e59bd9eda33be5e519c12cf2512b61817a430 |
|
MD5 | 24316ed2618708ef33e63cc4844d8558 |
|
BLAKE2b-256 | 74e015721cca2cdfa1aa5af3de5c75f6f1865dc33b243761cb077cbc1a072964 |
File details
Details for the file slow_learner-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: slow_learner-0.1.3-py3-none-any.whl
- Upload date:
- Size: 24.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2ea0b07a5712aefe14dd4d411fd82dc2a12ee9489195e0cb028a17df052e31a |
|
MD5 | 9f470748b815093cf403601de7c0442a |
|
BLAKE2b-256 | 6f51b48dfb0eb6dd7fef3a1fcbd1319cd16321201929184362117bddd9ddd701 |