Skip to main content

Infer JSON schemas from sample data

Project description

philiprehberger-schema-infer

Tests PyPI version License

Infer JSON schemas from sample data.

Installation

pip install philiprehberger-schema-infer

Usage

from philiprehberger_schema_infer import infer, infer_type, merge_schemas

samples = [
    {"name": "Alice", "age": 30, "active": True},
    {"name": "Bob", "age": 25, "email": "bob@test.com"},
]

schema = infer(samples)
# {
#   "type": "object",
#   "properties": {
#     "name": {"type": "string"},
#     "age": {"type": "integer"},
#     "active": {"type": "boolean"},
#     "email": {"type": "string", "format": "email"}
#   },
#   "required": ["age", "name"]
# }

# Single value
infer_type([1, 2, 3])
# {"type": "array", "items": {"type": "integer"}}

# Merge schemas
merged = merge_schemas(schema_a, schema_b)

API

Function / Class Description
infer(samples) Infer JSON Schema from list of dicts
infer_type(value) Infer type for a single value
merge_schemas(a, b) Merge two schemas

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

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

philiprehberger_schema_infer-0.1.6.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_schema_infer-0.1.6-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_schema_infer-0.1.6.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_schema_infer-0.1.6.tar.gz
Algorithm Hash digest
SHA256 de165126e540027db6ecfa0d46aa68feb3c5fcf680e2a78e5d0acd02fa2ec61a
MD5 397ace76d332fb1e183d8ddf4cbc8dc9
BLAKE2b-256 89b444a16d16ff1b7e8c9a24e982c9bef947f5380b95e751c67886ad3df9a8ea

See more details on using hashes here.

File details

Details for the file philiprehberger_schema_infer-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_schema_infer-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d801089937b40476c433eedc3b449c0b1fc4e2d4bb01a4d9994e1aa76b9a13f8
MD5 9af299dafabccfc936dc1978a4c84894
BLAKE2b-256 01f749b51e5b769a2d2e4114fa20f268bef061f500f44bc0122c4eb27f9e8a9c

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