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.
The CLI depends on Typer. Install Pandera with
the cli extra:
pipinstall'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 --backendnarwhals to
panderavalidate.
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.
panderaUsage: 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). │╰─────────────────────────────────────────────────────────────────────────────╯
validateUsage: 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 namespanderavalidate--schemaschema.yaml--datadata.csvValidate Parquet file with YAML schema with short form option namespandera validate -s schema.yml -d data.parquetValidate JSON file with JSON schema with short form option namespython -m pandera validate -s schema.json -d records.jsonValidate CSV file with YAML schema with Polars backend with long form optionnamespandera validate -s schema.yaml -d data.csv --backend polarsValidate a pandas or Polars schema through the Narwhals-powered backendpandera validate -s schema.yaml -d data.csv --backend narwhals--backend narwhals is equivalent to settingPANDERA_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. │╰─────────────────────────────────────────────────────────────────────────────╯
inferUsage: 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 filepanderainfer-ddata.csv-oschema.yamlInfer a schema from a Parquet file and write to a JSON filepanderainfer--datatable.parquet--outputschema.json--backendpolarsInfer a schema from a CSV file and write to a Python model filepanderainfer-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. │╰─────────────────────────────────────────────────────────────────────────────╯
generateUsage: 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 filepanderagenerate-sschema.yaml-osample.csvGenerate synthetic data from a JSON schema and write to a NetCDF filepanderagenerate--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.│╰─────────────────────────────────────────────────────────────────────────────╯
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).