CLI

The Pandera CLI can validate on-disk datasets against a serialized schema (YAML or JSON), infer a schema from data and write YAML, JSON, or a Python module, or generate synthetic tabular or xarray data from a pandas or xarray schema. It is useful in scripts and CI without writing Python glue code.

Installation

The CLI depends on Typer. Install Pandera with the cli extra:

pip install 'pandera[cli]'

You still need the appropriate dataframe library for the schema you validate (for example pandas for the default pandas-API schema). YAML schemas require pandera[io] (PyYAML). To validate pandas, Polars, Ibis, or PySpark SQL schemas through the Narwhals-powered backend, install pandera[narwhals] and pass --backend narwhals to pandera validate.

Serialized schemas carry an optional top-level api field declaring the underlying dataframe API of the data to validate (pandas, modin, dask, pyspark.pandas, polars, ibis, or pyspark.sql). The CLI uses it to choose the data loader and, by default, the validation backend; it defaults to pandas when the field is absent.

Refer to Validating data with the CLI to learn how to use the CLI.

Commands

pandera

pandera Usage: pandera [OPTIONS] COMMAND [ARGS]... Pandera command-line tools.                                                   ╭─ Options ───────────────────────────────────────────────────────────────────╮ --install-completionInstall completion for the current shell.     --show-completionShow completion for the current shell, to     copy it or customize the installation.        --helpShow this message and exit.                   ╰─────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ──────────────────────────────────────────────────────────────────╮ validateValidate a file against a serialized schema (YAML/JSON).          infer   Infer a schema from a data file and write YAML, JSON, or Python.  generateGenerate synthetic data from a serialized schema (hypothesis).    ╰─────────────────────────────────────────────────────────────────────────────╯

validate

validate Usage: pandera validate [OPTIONS] Validate a file against a serialized schema (YAML/JSON).                      On success, prints a summary of schema- and data-level checks (Richtables  when Rich is installed). On failure, prints which checks passed orfailed  plus failure details, then exits with a non-zero code. Examples: Validate CSV file with YAML schema with long form option names panderavalidate--schemaschema.yaml--datadata.csv Validate Parquet file with YAML schema with short form option names pandera validate -s schema.yml -d data.parquet Validate JSON file with JSON schema with short form option names python -m pandera validate -s schema.json -d records.json Validate CSV file with YAML schema with Polars backend with long form option names pandera validate -s schema.yaml -d data.csv --backend polars Validate a pandas or Polars schema through the Narwhals-powered backend pandera validate -s schema.yaml -d data.csv --backend narwhals --backend narwhals is equivalent to setting PANDERA_USE_NARWHALS_BACKEND=True. The report shows the validation backend that actually ran (e.g.Backend:  narwhals or Backend: pandas). ╭─ Options ───────────────────────────────────────────────────────────────────╮ *--schema-s<path>Path to schema file        (.yaml, .yml, or .json).   [required]                 *--data-d<path>Path to the dataset        (format must match         backend).                  [required]                 --backend-b<pandas|modin|dask|pysparValidation backend. A      k.pandas|pyspark.sql|poladataframe API (pandas,     rs|ibis|narwhals>modin, dask,               pyspark.pandas, polars,    ibis, pyspark.sql) must    match the schema's api     field; narwhals validates  pandas, polars, ibis, and  pyspark.sql schemas        through the                Narwhals-powered backend   (requires                  pandera[narwhals]).        Default: the schema's api. --helpShow this message and      exit.                      ╰─────────────────────────────────────────────────────────────────────────────╯

infer

infer Usage: pandera infer [OPTIONS] Infer a schema from a data file and write YAML, JSON, or Python.              Uses the same loaders as validate for each --backend. Pandas-APIbackends  infer from an in-memory pandas DataFrame (dask and modin maytrigger a full  compute / conversion). Examples: Infer a schema from a CSV file and write to a YAML file panderainfer-ddata.csv-oschema.yaml Infer a schema from a Parquet file and write to a JSON file panderainfer--datatable.parquet--outputschema.json--backendpolars Infer a schema from a CSV file and write to a Python model file panderainfer-ddata.csv-omodel.py--formatpy--script-typemodel ╭─ Options ───────────────────────────────────────────────────────────────────╮ *--data-d<path>Path to the dataset      (same extensions as      validate per backend).   [required]               *--output-o<path>Path to write the        inferred schema (.yaml,  .json, or .py).          [required]               --backend-b<pandas|modin|dask|pyspDataframe API to use for ark.pandas|pyspark.sql|loading data and for the polars|ibis|narwhals>output schema API        (narwhals is a           validation-only backend  and is not accepted      here).                   [default: pandas]        --format-f<yaml|json|py>Output format. Default:  from --output extension  (.yaml/.yml, .json,      .py).                    --script-type<schema|model>If --format py: emit     DataFrameSchema ("schema") or            DataFrameModel ("model").               [default: schema]        --helpShow this message and    exit.                    ╰─────────────────────────────────────────────────────────────────────────────╯

generate

generate Usage: pandera generate [OPTIONS] Generate synthetic data from a serialized schema (hypothesis).                Requires pandera[strategies] (hypothesis). Only pandas dataframeschemas and  xarraydata_array / dataset schemas are supported;other backends may be  added later. Examples: Generate synthetic data from a YAML schema and write to a CSV file panderagenerate-sschema.yaml-osample.csv Generate synthetic data from a JSON schema and write to a NetCDF file panderagenerate--schemads_schema.json--outputdata.nc--size5 ╭─ Options ───────────────────────────────────────────────────────────────────╮ *--schema-s<path>Path to a YAML or JSON      schema (pandas or xarray).  [required]                  *--output-o<path>Path to write generated     data. Extension selects     format: .csv, .json,        .parquet, .feather (pandas  or xarray); .nc for xarray  NetCDF.                     [required]                  --size-n<int>Number of rows for pandas   tables; default dimension   size for xarray synthetic   data.                       [default: 10]               --format-f<csv|json|parquet|featherOutput format. Default:     |netcdf>from --output extension.    Use netcdf for xarray       NetCDF when the path has no suffix.                     --helpShow this message and exit. ╰─────────────────────────────────────────────────────────────────────────────╯

Supported file combinations

Schema files must be YAML (with PyYAML installed) or JSON. Supported data extensions depend on the backend; common cases include CSV, Parquet, JSON, and Feather for pandas-like backends. Ibis is limited to CSV and Parquet in the CLI (see the implementation for details).

For more on serialization formats, see Schema persistence and IO Utilities.