Python API

Import the public classes from their defining modules:

from data_schemer.schema_projector import SchemaProjector, SchemaProjection
from data_schemer.schema_command_line import SchemaCommandLine

SchemaProjector

SchemaProjector(schema_definitions, *, schema_name=None, input_data=None,
                registry=None, source=None)

schema_definitions is a conventional Python dictionary in single-schema or named-schema form. schema_name selects a definition in named-schema form. registry supplies a DataCanon (DC) conversion registry. source supplies external-resource context for conventional conversion. An optional input_data DataCanon Instance (DCI) creates an initial projection. Schemas declared with pipeline: true accept a List DCI and return a PipelineProjection; ordinary schemas accept a Mapping DCI. The optional strict_input argument to get_projection() defaults to True.

MemberMeaning
get_projection(input_data, *, strict_input=True)Validate a Mapping or pipeline List DCI and return the corresponding projection; strictness applies to mapping fields and propagates to children
compile_child(name)Compile or return a reusable declared child projector
find_projectors_with_paths(name, include_self=False)Find compiled definitions by schema name, returning (path, projector) pairs; include_self is keyword-only
schema_nameSelected schema name
schema_variablesCopy of the compiled field metadata
allowed_typesSet of accepted DataCanon Type (DCT) constraint names
child_schema_namesAccumulated declared child names
child_projectorsSnapshot of child projectors compiled so far
conflictsCopy of the resolved conflict groups
projectionInitial projection, if input_data was supplied
data_dci, data, get_instance(callable)Access or construct from the initial projection

Accessing initial-projection members without an initial input raises DSUserError. Reusable projectors and per-input projections have distinct roles; passing a new input to get_projection() does not replace the initial projection.

For a field declared type: "Array", optional array_type constrains its portable element type, for example float64. It requires an exact match and preserves the supplied Array. This metadata is resolved during schema composition and validated before projection; defaults are checked as well.

SchemaProjection

Obtain a projection through projector.get_projection(input_dci).

MemberMeaning
input_dciOriginal complete Mapping DCI
data_dciProcessed local fields
dataConventional conversion of local fields
data_tree_dciComplete processed tree
data_treeConventional conversion of the complete tree
child_projectionsImmediate supplied children and their per-input results
child_dataImmediate children’s conventional local fields
get_instance(callable)Bind selected local arguments, convert them, and invoke the callable

Conventional views are computed on request. get_instance() selects fields before converting, so unrelated external references need not be materialized. See Application construction.

PipelineProjection

Obtain a pipeline projection through projector.get_projection(input_dci) for a schema declared with pipeline: true. The input is a List DCI of one-entry Mapping steps. Steps retain their order and may repeat.

input_dci is the original List; data_dci and data_tree_dci are the validated List including applicable default steps. data and data_tree are conventional views. Unlike SchemaProjection, child_projections returns ordered (position, name, projection) occurrences, and child_data returns ordered (position, name, data) occurrences. Pipeline projections can contain mapping or pipeline children.

See Pipeline schemas.

SchemaCommandLine

SchemaCommandLine(schema_definitions, target_class=None, schema_name=None,
                  argv=None, input_files_tag="input_files",
                  prog=None, registry=None, stdin_format="shorthand",
                  user_defaults_file=None)

Construction parses sources, validates the merged DCI, optionally constructs the target, calls _operations(), and handles requested attribute output. Omit argv to use sys.argv[1:]. prog selects the displayed executable name. stdin_format accepts "yaml" or "shorthand" for structured stdin, with Shorthand as the default. user_defaults_file optionally selects a Shorthand file containing SCL user defaults. The root CLI also supports --stdin-format, --fallback-format, --no-user-defaults, and --dump-cli. When schema-level strict_input enables the control, --strict-input {true,false} overrides its default for that invocation.

SchemaCommandLine (SCL) exposes input_dci, data_dci, data, data_tree_dci, data_tree, child_projections, and child_data from its projection. Additional members:

MemberMeaning
target_objConstructed target or None
raw_child_dataImmediate supplied child input DCIs
required_file_pathSelected required positional file, if enabled
required_file_contentApplication-specific text/bytes when requested; otherwise None
_operations()Subclass hook after construction and before attribute output
main(*args, debug=False, **kwargs)Class method returning zero on success or the caught DataSchemer (DS) user-error exit code

main() forwards arguments to the constructor. debug=True reraises caught DS user errors. Argparse help can exit through normal SystemExit(0) behavior.

Schema metadata helpers

The following helpers are available from data_schemer.schema_projector:

get_schema_variables(schema_name, schema_definitions, allowed_types=None, defaults=None)
get_schema_child_schemas(schema_name, schema_definitions)
get_schema_conflicts(schema_name, schema_definitions)
get_schema_print_attribute(schema_name, schema_definitions)
get_schema_strict_input(schema_name, schema_definitions)

get_schema_variables() resolves metadata. SchemaProjector performs additional compilation checks and converts defaults and choices to DCIs; use the projector when processing input. get_schema_strict_input() returns None if the CLI override is disabled, or a mapping containing the effective Boolean default when enabled.

For SCL tooling, compute_print_attribute_choices() is available from data_schemer.schema_command_line:

compute_print_attribute_choices(print_attribute, *, target_class, schema_vars)

It returns (choices, external_to_internal) for attribute validation and completion. Callers should reuse it when they need SCL’s naming rules.

Output formatting

SCL attribute output uses DC YAML interchange. Applications handle their own numerical reports. render_data.py, numpy_print.py, and SCL’s numerical report controls have been removed; see Output and application reports.