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.5.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.5-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_schema_infer-0.1.5.tar.gz
Algorithm Hash digest
SHA256 67f243aeacc705ac2aa7014515bafa2d56decd56d4da139412b38292b2ea6e72
MD5 44d334005db03481d7d8465e89125b5c
BLAKE2b-256 198677fc977f613796f456cd034933b4d4ba6c8629c779644e1866ab98892a46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_schema_infer-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 091db7825d54c937cfb65b9ad01a735a345a5ec8b5d98c91a1ed5056a290f753
MD5 b14083ba6e1d70d7110b6d81d5c2774e
BLAKE2b-256 c096baa60179f9367a86f562e23463dc977a37d0d60db73cdd54f0df29646942

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