Skip to main content

A toolkit to infer data schemas from samples

Project description

Schemarize

Schemarize is a Python package to infer, inspect, and serialize the schema of data files and objects—whether they’re JSON, CSV, Parquet, or DataFrames. It’s designed for simplicity: just call one method, get a schema, and export as JSON, YAML, or CSV.


Installation

Install from PyPI:

pip install schemarize

Quickstart

import pandas as pd
from schemarize import schemarize

df = pd.DataFrame({"a": [1, 2], "b": ["x", "y"]})
schema = schemarize(df)

print(schema.to_json())
print(schema.to_yaml())
print(schema.to_csv())

schema.save("my_schema.json")   # or .yaml, .csv

You can also pass a file path (CSV, JSON, Parquet, etc.):

schema = schemarize("data.csv")
print(schema.to_dict())

Main Function

schemarize(data, *, output="json", sample_size=None) -> Schema

  • data: File path, DataFrame, Arrow Table, or file-like object.
  • output: "json", "yaml", or "csv" (for future use; .to_*() preferred).
  • sample_size: Optionally limit number of records to inspect.

Returns a Schema object.


Schema Methods

The returned Schema object provides:

  • to_dict() – Return the schema as a Python dict.
  • to_json(pretty=True) – Serialize as JSON string.
  • to_yaml() – Serialize as YAML string.
  • to_csv() – Serialize as CSV string.
  • save(path, format=None) – Save to file, format auto-detected by extension.

Example: Saving a schema

schema.save("my_schema.yaml")
schema.save("my_schema.csv")

Supported Inputs

  • Pandas DataFrames
  • PyArrow Tables
  • File paths: CSV, JSON, JSONL, Parquet (compressed files supported)
  • File-like objects

Supported Outputs

  • JSON
  • YAML (requires pyyaml)
  • CSV (flat field view)

License

MIT


Links

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

schemarize-0.1.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

schemarize-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file schemarize-0.1.0.tar.gz.

File metadata

  • Download URL: schemarize-0.1.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for schemarize-0.1.0.tar.gz
Algorithm Hash digest
SHA256 81d7a8fa124a759206946220cd7737c393ebc5984a2e0534589d214549d8c07b
MD5 77b34045e6cd3e87776af9f6c404c263
BLAKE2b-256 292750dbc4cb610157b80f89099d5ffc4a4ca37f69a2aedd128df1f59181b857

See more details on using hashes here.

File details

Details for the file schemarize-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: schemarize-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for schemarize-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d7c14f02113b4acab20bdac84211edc3ccdf6e574b8d6f567b70853ec9f6b73
MD5 354edfd505f6110833b41049de29ff9c
BLAKE2b-256 c78ca66a7848df4540c2a2583ac8ad1126f7749e080f94ed0de04a5cbcf50790

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