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

  • 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.4.tar.gz (4.8 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.4-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_schema_infer-0.1.4.tar.gz
Algorithm Hash digest
SHA256 389057a2af0582433a7fea0a4112792dc36b65cb2672f73c20a0054f22f16301
MD5 01e99be31c148ed7e36955f6766ec0ec
BLAKE2b-256 576c4995ad1c3c57417c499baea20461f7a667cc19b9f396fe55effbe9f14d38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_schema_infer-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8041874a3f85cfca59ab77bea05bfca907a57c686bec33a70d9cc4a3a78098e9
MD5 ef853378d4caf137695d30638c1ee071
BLAKE2b-256 5ca5d79e16b59a9f8a42a2e1df8dafa5fca6cef8849bc122a20977f02675fa8f

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