Skip to main contentIBM Quantum Documentation
This page is from an old version of Qiskit SDK and does not exist in the latest version. We recommend you migrate to the latest version. See the release notes for more information.
Important

IBM Quantum Platform is moving and this version will be sunset on July 1. To get started on the new platform, read the migration guide.

bind_schema

bind_schema(schema, **kwargs)

GitHub

Class decorator for adding schema validation to its instances.

The decorator acts on the model class by adding:

  • a class attribute schema with the schema used for validation
  • a class attribute shallow_schema used for validation during instantiation.

The same schema cannot be bound more than once. If you need to reuse a schema for a different class, create a new schema subclassing the one you want to reuse and leave the new empty:

class MySchema(BaseSchema):
    title = String()
 
class AnotherSchema(MySchema):
    pass
 
@bind_schema(MySchema):
class MyModel(BaseModel):
    pass
 
@bind_schema(AnotherSchema):
class AnotherModel(BaseModel):
    pass
Note

By default, models decorated with this decorator are validated during instantiation. If validate=False is passed to the constructor, this validation will not be performed.

Parameters

  • schema (class) – the schema class used for validation.
  • **kwargs – Additional attributes for the marshmallow.Schema initializer.

Raises

ValueError – when trying to bind the same schema more than once.

Returns

the same class with validation capabilities.

Return type

type

Was this page helpful?
Report a bug or request content on GitHub.