Infer JSON schemas from sample data
Project description
philiprehberger-schema-infer
Infer JSON schemas from sample data.
Installation
pip install philiprehberger-schema-infer
Usage
Infer schema from samples
from philiprehberger_schema_infer import infer
samples = [
{"name": "Alice", "age": 30, "active": True},
{"name": "Bob", "age": 25, "email": "bob@test.com"},
]
schema = infer(samples)
# {
# "type": "object",
# "properties": {
# "name": {"type": "string", "minLength": 3, "maxLength": 5},
# "age": {"type": "integer", "minimum": 25, "maximum": 30},
# "active": {"type": "boolean"},
# "email": {"type": "string", "format": "email", ...}
# },
# "required": ["age", "name"]
# }
Full JSON Schema output
from philiprehberger_schema_infer import to_json_schema
schema = to_json_schema(samples)
# {
# "$schema": "https://json-schema.org/draft/2020-12/schema",
# "type": "object",
# "properties": { ... },
# "required": [...]
# }
Single value type inference
from philiprehberger_schema_infer import infer_type
infer_type([1, 2, 3])
# {"type": "array", "items": {"type": "integer"}}
Merge schemas
from philiprehberger_schema_infer import merge_schemas
merged = merge_schemas(schema_a, schema_b)
API
| Name | Description |
|---|---|
infer(samples) |
Infer JSON Schema from a list of dicts. Includes minimum/maximum for numbers and minLength/maxLength for strings. |
infer_type(value) |
Infer schema type for a single value |
merge_schemas(a, b) |
Merge two schemas into one accepting either |
to_json_schema(samples) |
Wraps infer() output with $schema URI for draft 2020-12 |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this package useful, consider starring the repository.
License
Project details
Release history Release notifications | RSS feed
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 philiprehberger_schema_infer-0.2.0.tar.gz.
File metadata
- Download URL: philiprehberger_schema_infer-0.2.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ddd9d74c0daf15fc2d7975a4ff581419e2628c05fe03b715be674b2a1972dfb
|
|
| MD5 |
b63396cc0a007477a8f41d378efdec53
|
|
| BLAKE2b-256 |
84262f21dbee02115e03238f7ce1528de04e9078432e26cc2c1c5260bd55556e
|
File details
Details for the file philiprehberger_schema_infer-0.2.0-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_schema_infer-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb46191441a3cd1a1f64b0e58888e80c2e998b700aa24d7538f6f5c4978fd326
|
|
| MD5 |
f2b3d132adda91b1850fefecfd8200b2
|
|
| BLAKE2b-256 |
e06bc8d15ad7e0f8a74f88f6c5f64555d04b3ccce300b5e9c46e22190b76ca7c
|