API¶
Error Handler¶
Media Handler¶
- class api.media_handler.XML_Handler(dumps=None, loads=None)[source]¶
- deserialize(stream, content_type, content_length)[source]¶
Deserialize the
falcon.Request
body.- Args:
stream (object): Input data to deserialize. content_type (str): Type of request content. content_length (int): Length of request content.
- Returns:
object: A deserialized object.
- serialize(media, content_type)¶
Serialize the media object on a
falcon.Response
- Args:
media (object): A serializable object. content_type (str): Type of response content.
- Returns:
bytes: The resulting serialized bytes from the input object.
- class api.media_handler.YAML_Handler(dumps=None, loads=None)[source]¶
- deserialize(stream, content_type, content_length)[source]¶
Deserialize the
falcon.Request
body.- Args:
stream (object): Input data to deserialize. content_type (str): Type of request content. content_length (int): Length of request content.
- Returns:
object: A deserialized object.
- serialize(media, content_type)¶
Serialize the media object on a
falcon.Response
- Args:
media (object): A serializable object. content_type (str): Type of response content.
- Returns:
bytes: The resulting serialized bytes from the input object.
Middleware¶
Spec¶
Docstring¶
Document¶
- class document.base.Base_Document(meta=None, **kwargs)[source]¶
- delete(using=None, index=None, **kwargs)¶
Delete the instance in elasticsearch.
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.delete
unchanged.
- classmethod get(id, using=None, index=None, **kwargs)¶
Retrieve a single document from elasticsearch using it’s
id
.- Parameters
id –
id
of the document to be retrievedindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.get
unchanged.
- classmethod init(index=None, using=None)¶
Create the index and populate the mappings in elasticsearch.
- classmethod mget(docs, using=None, index=None, raise_on_error=True, missing='none', **kwargs)¶
Retrieve multiple document by their
id
s. Returns a list of instances in the same order as requested.- Parameters
docs – list of
id
s of the documents to be retrieved or a list of document specifications as per https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.htmlindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
missing – what to do when one of the documents requested is not found. Valid options are
'none'
(useNone
),'raise'
(raiseNotFoundError
) or'skip'
(ignore the missing document).
Any additional keyword arguments will be passed to
Elasticsearch.mget
unchanged.
- save(using=None, index=None, validate=True, skip_empty=True, **kwargs)¶
Save the document into elasticsearch. If the document doesn’t exist it is created, it is overwritten otherwise. Returns
True
if this operations resulted in new document being created.- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
validate – set to
False
to skip validating the documentskip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
Any additional keyword arguments will be passed to
Elasticsearch.index
unchanged.:return operation result created/updated
- classmethod search(using=None, index=None)¶
Create an
Search
instance that will search over thisDocument
.
- to_dict(include_meta=False, skip_empty=True)¶
Serialize the instance into a dictionary so that it can be saved in elasticsearch.
- Parameters
include_meta – if set to
True
will include all the metadata (_index
,_id
etc). Otherwise just the document’s data is serialized. This is useful when passing multiple instances intoelasticsearch.helpers.bulk
.skip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
- update(using=None, index=None, detect_noop=True, doc_as_upsert=False, refresh=False, retry_on_conflict=None, script=None, script_id=None, scripted_upsert=False, upsert=None, **fields)¶
Partial update of the document, specify fields you wish to update and both the instance and the document in elasticsearch will be updated:
doc = MyDocument(title='Document Title!') doc.save() doc.update(title='New Document Title!')
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
detect_noop – Set to
False
to disable noop detection.refresh – Control when the changes made by this request are visible to search. Set to
True
for immediate effect.retry_on_conflict – In between the get and indexing phases of the update, it is possible that another process might have already updated the same document. By default, the update will fail with a version conflict exception. The retry_on_conflict parameter controls how many times to retry the update before finally throwing an exception.
doc_as_upsert – Instead of sending a partial doc plus an upsert doc, setting doc_as_upsert to true will use the contents of doc as the upsert value
:return operation result noop/updated
Agent¶
- class document.agent.catalog.Agent_Catalog_Document(meta=None, **kwargs)[source]¶
Represents an agent in the catalog.
- delete(using=None, index=None, **kwargs)¶
Delete the instance in elasticsearch.
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.delete
unchanged.
- classmethod get(id, using=None, index=None, **kwargs)¶
Retrieve a single document from elasticsearch using it’s
id
.- Parameters
id –
id
of the document to be retrievedindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.get
unchanged.
- classmethod init(index=None, using=None)¶
Create the index and populate the mappings in elasticsearch.
- classmethod mget(docs, using=None, index=None, raise_on_error=True, missing='none', **kwargs)¶
Retrieve multiple document by their
id
s. Returns a list of instances in the same order as requested.- Parameters
docs – list of
id
s of the documents to be retrieved or a list of document specifications as per https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.htmlindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
missing – what to do when one of the documents requested is not found. Valid options are
'none'
(useNone
),'raise'
(raiseNotFoundError
) or'skip'
(ignore the missing document).
Any additional keyword arguments will be passed to
Elasticsearch.mget
unchanged.
- save(using=None, index=None, validate=True, skip_empty=True, **kwargs)¶
Save the document into elasticsearch. If the document doesn’t exist it is created, it is overwritten otherwise. Returns
True
if this operations resulted in new document being created.- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
validate – set to
False
to skip validating the documentskip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
Any additional keyword arguments will be passed to
Elasticsearch.index
unchanged.:return operation result created/updated
- classmethod search(using=None, index=None)¶
Create an
Search
instance that will search over thisDocument
.
- to_dict(include_meta=False, skip_empty=True)¶
Serialize the instance into a dictionary so that it can be saved in elasticsearch.
- Parameters
include_meta – if set to
True
will include all the metadata (_index
,_id
etc). Otherwise just the document’s data is serialized. This is useful when passing multiple instances intoelasticsearch.helpers.bulk
.skip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
- update(using=None, index=None, detect_noop=True, doc_as_upsert=False, refresh=False, retry_on_conflict=None, script=None, script_id=None, scripted_upsert=False, upsert=None, **fields)¶
Partial update of the document, specify fields you wish to update and both the instance and the document in elasticsearch will be updated:
doc = MyDocument(title='Document Title!') doc.save() doc.update(title='New Document Title!')
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
detect_noop – Set to
False
to disable noop detection.refresh – Control when the changes made by this request are visible to search. Set to
True
for immediate effect.retry_on_conflict – In between the get and indexing phases of the update, it is possible that another process might have already updated the same document. By default, the update will fail with a version conflict exception. The retry_on_conflict parameter controls how many times to retry the update before finally throwing an exception.
doc_as_upsert – Instead of sending a partial doc plus an upsert doc, setting doc_as_upsert to true will use the contents of doc as the upsert value
:return operation result noop/updated
- class document.agent.instance.Agent_Instance_Document(meta=None, **kwargs)[source]¶
Represents an agent instance installed in an execution environment.
- delete(using=None, index=None, **kwargs)¶
Delete the instance in elasticsearch.
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.delete
unchanged.
- classmethod get(id, using=None, index=None, **kwargs)¶
Retrieve a single document from elasticsearch using it’s
id
.- Parameters
id –
id
of the document to be retrievedindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.get
unchanged.
- classmethod init(index=None, using=None)¶
Create the index and populate the mappings in elasticsearch.
- classmethod mget(docs, using=None, index=None, raise_on_error=True, missing='none', **kwargs)¶
Retrieve multiple document by their
id
s. Returns a list of instances in the same order as requested.- Parameters
docs – list of
id
s of the documents to be retrieved or a list of document specifications as per https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.htmlindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
missing – what to do when one of the documents requested is not found. Valid options are
'none'
(useNone
),'raise'
(raiseNotFoundError
) or'skip'
(ignore the missing document).
Any additional keyword arguments will be passed to
Elasticsearch.mget
unchanged.
- save(using=None, index=None, validate=True, skip_empty=True, **kwargs)¶
Save the document into elasticsearch. If the document doesn’t exist it is created, it is overwritten otherwise. Returns
True
if this operations resulted in new document being created.- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
validate – set to
False
to skip validating the documentskip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
Any additional keyword arguments will be passed to
Elasticsearch.index
unchanged.:return operation result created/updated
- classmethod search(using=None, index=None)¶
Create an
Search
instance that will search over thisDocument
.
- to_dict(include_meta=False, skip_empty=True)¶
Serialize the instance into a dictionary so that it can be saved in elasticsearch.
- Parameters
include_meta – if set to
True
will include all the metadata (_index
,_id
etc). Otherwise just the document’s data is serialized. This is useful when passing multiple instances intoelasticsearch.helpers.bulk
.skip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
- update(using=None, index=None, detect_noop=True, doc_as_upsert=False, refresh=False, retry_on_conflict=None, script=None, script_id=None, scripted_upsert=False, upsert=None, **fields)¶
Partial update of the document, specify fields you wish to update and both the instance and the document in elasticsearch will be updated:
doc = MyDocument(title='Document Title!') doc.save() doc.update(title='New Document Title!')
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
detect_noop – Set to
False
to disable noop detection.refresh – Control when the changes made by this request are visible to search. Set to
True
for immediate effect.retry_on_conflict – In between the get and indexing phases of the update, it is possible that another process might have already updated the same document. By default, the update will fail with a version conflict exception. The retry_on_conflict parameter controls how many times to retry the update before finally throwing an exception.
doc_as_upsert – Instead of sending a partial doc plus an upsert doc, setting doc_as_upsert to true will use the contents of doc as the upsert value
:return operation result noop/updated
eBPF Program¶
- class document.ebpf_program.catalog.eBPF_Program_Catalog_Document(meta=None, **kwargs)[source]¶
Represents an eBPF program in the catalog.
- delete(using=None, index=None, **kwargs)¶
Delete the instance in elasticsearch.
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.delete
unchanged.
- classmethod get(id, using=None, index=None, **kwargs)¶
Retrieve a single document from elasticsearch using it’s
id
.- Parameters
id –
id
of the document to be retrievedindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.get
unchanged.
- classmethod init(index=None, using=None)¶
Create the index and populate the mappings in elasticsearch.
- classmethod mget(docs, using=None, index=None, raise_on_error=True, missing='none', **kwargs)¶
Retrieve multiple document by their
id
s. Returns a list of instances in the same order as requested.- Parameters
docs – list of
id
s of the documents to be retrieved or a list of document specifications as per https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.htmlindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
missing – what to do when one of the documents requested is not found. Valid options are
'none'
(useNone
),'raise'
(raiseNotFoundError
) or'skip'
(ignore the missing document).
Any additional keyword arguments will be passed to
Elasticsearch.mget
unchanged.
- save(using=None, index=None, validate=True, skip_empty=True, **kwargs)¶
Save the document into elasticsearch. If the document doesn’t exist it is created, it is overwritten otherwise. Returns
True
if this operations resulted in new document being created.- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
validate – set to
False
to skip validating the documentskip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
Any additional keyword arguments will be passed to
Elasticsearch.index
unchanged.:return operation result created/updated
- classmethod search(using=None, index=None)¶
Create an
Search
instance that will search over thisDocument
.
- to_dict(include_meta=False, skip_empty=True)¶
Serialize the instance into a dictionary so that it can be saved in elasticsearch.
- Parameters
include_meta – if set to
True
will include all the metadata (_index
,_id
etc). Otherwise just the document’s data is serialized. This is useful when passing multiple instances intoelasticsearch.helpers.bulk
.skip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
- update(using=None, index=None, detect_noop=True, doc_as_upsert=False, refresh=False, retry_on_conflict=None, script=None, script_id=None, scripted_upsert=False, upsert=None, **fields)¶
Partial update of the document, specify fields you wish to update and both the instance and the document in elasticsearch will be updated:
doc = MyDocument(title='Document Title!') doc.save() doc.update(title='New Document Title!')
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
detect_noop – Set to
False
to disable noop detection.refresh – Control when the changes made by this request are visible to search. Set to
True
for immediate effect.retry_on_conflict – In between the get and indexing phases of the update, it is possible that another process might have already updated the same document. By default, the update will fail with a version conflict exception. The retry_on_conflict parameter controls how many times to retry the update before finally throwing an exception.
doc_as_upsert – Instead of sending a partial doc plus an upsert doc, setting doc_as_upsert to true will use the contents of doc as the upsert value
:return operation result noop/updated
- class document.ebpf_program.instance.eBPF_Program_Instance_Document(meta=None, **kwargs)[source]¶
Represents an eBPF program installed in an execution environment.
- delete(using=None, index=None, **kwargs)¶
Delete the instance in elasticsearch.
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.delete
unchanged.
- classmethod get(id, using=None, index=None, **kwargs)¶
Retrieve a single document from elasticsearch using it’s
id
.- Parameters
id –
id
of the document to be retrievedindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.get
unchanged.
- classmethod init(index=None, using=None)¶
Create the index and populate the mappings in elasticsearch.
- classmethod mget(docs, using=None, index=None, raise_on_error=True, missing='none', **kwargs)¶
Retrieve multiple document by their
id
s. Returns a list of instances in the same order as requested.- Parameters
docs – list of
id
s of the documents to be retrieved or a list of document specifications as per https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.htmlindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
missing – what to do when one of the documents requested is not found. Valid options are
'none'
(useNone
),'raise'
(raiseNotFoundError
) or'skip'
(ignore the missing document).
Any additional keyword arguments will be passed to
Elasticsearch.mget
unchanged.
- save(using=None, index=None, validate=True, skip_empty=True, **kwargs)¶
Save the document into elasticsearch. If the document doesn’t exist it is created, it is overwritten otherwise. Returns
True
if this operations resulted in new document being created.- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
validate – set to
False
to skip validating the documentskip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
Any additional keyword arguments will be passed to
Elasticsearch.index
unchanged.:return operation result created/updated
- classmethod search(using=None, index=None)¶
Create an
Search
instance that will search over thisDocument
.
- to_dict(include_meta=False, skip_empty=True)¶
Serialize the instance into a dictionary so that it can be saved in elasticsearch.
- Parameters
include_meta – if set to
True
will include all the metadata (_index
,_id
etc). Otherwise just the document’s data is serialized. This is useful when passing multiple instances intoelasticsearch.helpers.bulk
.skip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
- update(using=None, index=None, detect_noop=True, doc_as_upsert=False, refresh=False, retry_on_conflict=None, script=None, script_id=None, scripted_upsert=False, upsert=None, **fields)¶
Partial update of the document, specify fields you wish to update and both the instance and the document in elasticsearch will be updated:
doc = MyDocument(title='Document Title!') doc.save() doc.update(title='New Document Title!')
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
detect_noop – Set to
False
to disable noop detection.refresh – Control when the changes made by this request are visible to search. Set to
True
for immediate effect.retry_on_conflict – In between the get and indexing phases of the update, it is possible that another process might have already updated the same document. By default, the update will fail with a version conflict exception. The retry_on_conflict parameter controls how many times to retry the update before finally throwing an exception.
doc_as_upsert – Instead of sending a partial doc plus an upsert doc, setting doc_as_upsert to true will use the contents of doc as the upsert value
:return operation result noop/updated
Connection¶
- class document.connection.Connection_Document(meta=None, **kwargs)[source]¶
Represents an connection between execution environments and network links.
- delete(using=None, index=None, **kwargs)¶
Delete the instance in elasticsearch.
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.delete
unchanged.
- classmethod get(id, using=None, index=None, **kwargs)¶
Retrieve a single document from elasticsearch using it’s
id
.- Parameters
id –
id
of the document to be retrievedindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.get
unchanged.
- classmethod init(index=None, using=None)¶
Create the index and populate the mappings in elasticsearch.
- classmethod mget(docs, using=None, index=None, raise_on_error=True, missing='none', **kwargs)¶
Retrieve multiple document by their
id
s. Returns a list of instances in the same order as requested.- Parameters
docs – list of
id
s of the documents to be retrieved or a list of document specifications as per https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.htmlindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
missing – what to do when one of the documents requested is not found. Valid options are
'none'
(useNone
),'raise'
(raiseNotFoundError
) or'skip'
(ignore the missing document).
Any additional keyword arguments will be passed to
Elasticsearch.mget
unchanged.
- save(using=None, index=None, validate=True, skip_empty=True, **kwargs)¶
Save the document into elasticsearch. If the document doesn’t exist it is created, it is overwritten otherwise. Returns
True
if this operations resulted in new document being created.- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
validate – set to
False
to skip validating the documentskip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
Any additional keyword arguments will be passed to
Elasticsearch.index
unchanged.:return operation result created/updated
- classmethod search(using=None, index=None)¶
Create an
Search
instance that will search over thisDocument
.
- to_dict(include_meta=False, skip_empty=True)¶
Serialize the instance into a dictionary so that it can be saved in elasticsearch.
- Parameters
include_meta – if set to
True
will include all the metadata (_index
,_id
etc). Otherwise just the document’s data is serialized. This is useful when passing multiple instances intoelasticsearch.helpers.bulk
.skip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
- update(using=None, index=None, detect_noop=True, doc_as_upsert=False, refresh=False, retry_on_conflict=None, script=None, script_id=None, scripted_upsert=False, upsert=None, **fields)¶
Partial update of the document, specify fields you wish to update and both the instance and the document in elasticsearch will be updated:
doc = MyDocument(title='Document Title!') doc.save() doc.update(title='New Document Title!')
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
detect_noop – Set to
False
to disable noop detection.refresh – Control when the changes made by this request are visible to search. Set to
True
for immediate effect.retry_on_conflict – In between the get and indexing phases of the update, it is possible that another process might have already updated the same document. By default, the update will fail with a version conflict exception. The retry_on_conflict parameter controls how many times to retry the update before finally throwing an exception.
doc_as_upsert – Instead of sending a partial doc plus an upsert doc, setting doc_as_upsert to true will use the contents of doc as the upsert value
:return operation result noop/updated
Data¶
- class document.data.Data_Document(meta=None, **kwargs)[source]¶
Represents the stored data.
- delete(using=None, index=None, **kwargs)¶
Delete the instance in elasticsearch.
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.delete
unchanged.
- classmethod get(id, using=None, index=None, **kwargs)¶
Retrieve a single document from elasticsearch using it’s
id
.- Parameters
id –
id
of the document to be retrievedindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.get
unchanged.
- classmethod init(index=None, using=None)¶
Create the index and populate the mappings in elasticsearch.
- classmethod mget(docs, using=None, index=None, raise_on_error=True, missing='none', **kwargs)¶
Retrieve multiple document by their
id
s. Returns a list of instances in the same order as requested.- Parameters
docs – list of
id
s of the documents to be retrieved or a list of document specifications as per https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.htmlindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
missing – what to do when one of the documents requested is not found. Valid options are
'none'
(useNone
),'raise'
(raiseNotFoundError
) or'skip'
(ignore the missing document).
Any additional keyword arguments will be passed to
Elasticsearch.mget
unchanged.
- save(using=None, index=None, validate=True, skip_empty=True, **kwargs)¶
Save the document into elasticsearch. If the document doesn’t exist it is created, it is overwritten otherwise. Returns
True
if this operations resulted in new document being created.- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
validate – set to
False
to skip validating the documentskip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
Any additional keyword arguments will be passed to
Elasticsearch.index
unchanged.:return operation result created/updated
- classmethod search(using=None, index=None)¶
Create an
Search
instance that will search over thisDocument
.
- to_dict(include_meta=False, skip_empty=True)¶
Serialize the instance into a dictionary so that it can be saved in elasticsearch.
- Parameters
include_meta – if set to
True
will include all the metadata (_index
,_id
etc). Otherwise just the document’s data is serialized. This is useful when passing multiple instances intoelasticsearch.helpers.bulk
.skip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
- update(using=None, index=None, detect_noop=True, doc_as_upsert=False, refresh=False, retry_on_conflict=None, script=None, script_id=None, scripted_upsert=False, upsert=None, **fields)¶
Partial update of the document, specify fields you wish to update and both the instance and the document in elasticsearch will be updated:
doc = MyDocument(title='Document Title!') doc.save() doc.update(title='New Document Title!')
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
detect_noop – Set to
False
to disable noop detection.refresh – Control when the changes made by this request are visible to search. Set to
True
for immediate effect.retry_on_conflict – In between the get and indexing phases of the update, it is possible that another process might have already updated the same document. By default, the update will fail with a version conflict exception. The retry_on_conflict parameter controls how many times to retry the update before finally throwing an exception.
doc_as_upsert – Instead of sending a partial doc plus an upsert doc, setting doc_as_upsert to true will use the contents of doc as the upsert value
:return operation result noop/updated
Execution Environment¶
- class document.exec_env.Exec_Env_Document(meta=None, **kwargs)[source]¶
Represents an execution environment.
- delete(using=None, index=None, **kwargs)¶
Delete the instance in elasticsearch.
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.delete
unchanged.
- classmethod get(id, using=None, index=None, **kwargs)¶
Retrieve a single document from elasticsearch using it’s
id
.- Parameters
id –
id
of the document to be retrievedindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.get
unchanged.
- classmethod init(index=None, using=None)¶
Create the index and populate the mappings in elasticsearch.
- classmethod mget(docs, using=None, index=None, raise_on_error=True, missing='none', **kwargs)¶
Retrieve multiple document by their
id
s. Returns a list of instances in the same order as requested.- Parameters
docs – list of
id
s of the documents to be retrieved or a list of document specifications as per https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.htmlindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
missing – what to do when one of the documents requested is not found. Valid options are
'none'
(useNone
),'raise'
(raiseNotFoundError
) or'skip'
(ignore the missing document).
Any additional keyword arguments will be passed to
Elasticsearch.mget
unchanged.
- save(using=None, index=None, validate=True, skip_empty=True, **kwargs)¶
Save the document into elasticsearch. If the document doesn’t exist it is created, it is overwritten otherwise. Returns
True
if this operations resulted in new document being created.- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
validate – set to
False
to skip validating the documentskip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
Any additional keyword arguments will be passed to
Elasticsearch.index
unchanged.:return operation result created/updated
- classmethod search(using=None, index=None)¶
Create an
Search
instance that will search over thisDocument
.
- to_dict(include_meta=False, skip_empty=True)¶
Serialize the instance into a dictionary so that it can be saved in elasticsearch.
- Parameters
include_meta – if set to
True
will include all the metadata (_index
,_id
etc). Otherwise just the document’s data is serialized. This is useful when passing multiple instances intoelasticsearch.helpers.bulk
.skip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
- update(using=None, index=None, detect_noop=True, doc_as_upsert=False, refresh=False, retry_on_conflict=None, script=None, script_id=None, scripted_upsert=False, upsert=None, **fields)¶
Partial update of the document, specify fields you wish to update and both the instance and the document in elasticsearch will be updated:
doc = MyDocument(title='Document Title!') doc.save() doc.update(title='New Document Title!')
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
detect_noop – Set to
False
to disable noop detection.refresh – Control when the changes made by this request are visible to search. Set to
True
for immediate effect.retry_on_conflict – In between the get and indexing phases of the update, it is possible that another process might have already updated the same document. By default, the update will fail with a version conflict exception. The retry_on_conflict parameter controls how many times to retry the update before finally throwing an exception.
doc_as_upsert – Instead of sending a partial doc plus an upsert doc, setting doc_as_upsert to true will use the contents of doc as the upsert value
:return operation result noop/updated
- class document.exec_env.Exec_Env_Type_Document(meta=None, **kwargs)[source]¶
Type of execution environment. Example: virtual machine or container.
- delete(using=None, index=None, **kwargs)¶
Delete the instance in elasticsearch.
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.delete
unchanged.
- classmethod get(id, using=None, index=None, **kwargs)¶
Retrieve a single document from elasticsearch using it’s
id
.- Parameters
id –
id
of the document to be retrievedindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.get
unchanged.
- classmethod init(index=None, using=None)¶
Create the index and populate the mappings in elasticsearch.
- classmethod mget(docs, using=None, index=None, raise_on_error=True, missing='none', **kwargs)¶
Retrieve multiple document by their
id
s. Returns a list of instances in the same order as requested.- Parameters
docs – list of
id
s of the documents to be retrieved or a list of document specifications as per https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.htmlindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
missing – what to do when one of the documents requested is not found. Valid options are
'none'
(useNone
),'raise'
(raiseNotFoundError
) or'skip'
(ignore the missing document).
Any additional keyword arguments will be passed to
Elasticsearch.mget
unchanged.
- save(using=None, index=None, validate=True, skip_empty=True, **kwargs)¶
Save the document into elasticsearch. If the document doesn’t exist it is created, it is overwritten otherwise. Returns
True
if this operations resulted in new document being created.- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
validate – set to
False
to skip validating the documentskip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
Any additional keyword arguments will be passed to
Elasticsearch.index
unchanged.:return operation result created/updated
- classmethod search(using=None, index=None)¶
Create an
Search
instance that will search over thisDocument
.
- to_dict(include_meta=False, skip_empty=True)¶
Serialize the instance into a dictionary so that it can be saved in elasticsearch.
- Parameters
include_meta – if set to
True
will include all the metadata (_index
,_id
etc). Otherwise just the document’s data is serialized. This is useful when passing multiple instances intoelasticsearch.helpers.bulk
.skip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
- update(using=None, index=None, detect_noop=True, doc_as_upsert=False, refresh=False, retry_on_conflict=None, script=None, script_id=None, scripted_upsert=False, upsert=None, **fields)¶
Partial update of the document, specify fields you wish to update and both the instance and the document in elasticsearch will be updated:
doc = MyDocument(title='Document Title!') doc.save() doc.update(title='New Document Title!')
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
detect_noop – Set to
False
to disable noop detection.refresh – Control when the changes made by this request are visible to search. Set to
True
for immediate effect.retry_on_conflict – In between the get and indexing phases of the update, it is possible that another process might have already updated the same document. By default, the update will fail with a version conflict exception. The retry_on_conflict parameter controls how many times to retry the update before finally throwing an exception.
doc_as_upsert – Instead of sending a partial doc plus an upsert doc, setting doc_as_upsert to true will use the contents of doc as the upsert value
:return operation result noop/updated
Network Link¶
- class document.network_link.Network_Link_Document(meta=None, **kwargs)[source]¶
Represents a network link.
- delete(using=None, index=None, **kwargs)¶
Delete the instance in elasticsearch.
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.delete
unchanged.
- classmethod get(id, using=None, index=None, **kwargs)¶
Retrieve a single document from elasticsearch using it’s
id
.- Parameters
id –
id
of the document to be retrievedindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.get
unchanged.
- classmethod init(index=None, using=None)¶
Create the index and populate the mappings in elasticsearch.
- classmethod mget(docs, using=None, index=None, raise_on_error=True, missing='none', **kwargs)¶
Retrieve multiple document by their
id
s. Returns a list of instances in the same order as requested.- Parameters
docs – list of
id
s of the documents to be retrieved or a list of document specifications as per https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.htmlindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
missing – what to do when one of the documents requested is not found. Valid options are
'none'
(useNone
),'raise'
(raiseNotFoundError
) or'skip'
(ignore the missing document).
Any additional keyword arguments will be passed to
Elasticsearch.mget
unchanged.
- save(using=None, index=None, validate=True, skip_empty=True, **kwargs)¶
Save the document into elasticsearch. If the document doesn’t exist it is created, it is overwritten otherwise. Returns
True
if this operations resulted in new document being created.- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
validate – set to
False
to skip validating the documentskip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
Any additional keyword arguments will be passed to
Elasticsearch.index
unchanged.:return operation result created/updated
- classmethod search(using=None, index=None)¶
Create an
Search
instance that will search over thisDocument
.
- to_dict(include_meta=False, skip_empty=True)¶
Serialize the instance into a dictionary so that it can be saved in elasticsearch.
- Parameters
include_meta – if set to
True
will include all the metadata (_index
,_id
etc). Otherwise just the document’s data is serialized. This is useful when passing multiple instances intoelasticsearch.helpers.bulk
.skip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
- update(using=None, index=None, detect_noop=True, doc_as_upsert=False, refresh=False, retry_on_conflict=None, script=None, script_id=None, scripted_upsert=False, upsert=None, **fields)¶
Partial update of the document, specify fields you wish to update and both the instance and the document in elasticsearch will be updated:
doc = MyDocument(title='Document Title!') doc.save() doc.update(title='New Document Title!')
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
detect_noop – Set to
False
to disable noop detection.refresh – Control when the changes made by this request are visible to search. Set to
True
for immediate effect.retry_on_conflict – In between the get and indexing phases of the update, it is possible that another process might have already updated the same document. By default, the update will fail with a version conflict exception. The retry_on_conflict parameter controls how many times to retry the update before finally throwing an exception.
doc_as_upsert – Instead of sending a partial doc plus an upsert doc, setting doc_as_upsert to true will use the contents of doc as the upsert value
:return operation result noop/updated
- class document.network_link.Network_Link_Type_Document(meta=None, **kwargs)[source]¶
Represents a network link type.
- delete(using=None, index=None, **kwargs)¶
Delete the instance in elasticsearch.
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.delete
unchanged.
- classmethod get(id, using=None, index=None, **kwargs)¶
Retrieve a single document from elasticsearch using it’s
id
.- Parameters
id –
id
of the document to be retrievedindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
Any additional keyword arguments will be passed to
Elasticsearch.get
unchanged.
- classmethod init(index=None, using=None)¶
Create the index and populate the mappings in elasticsearch.
- classmethod mget(docs, using=None, index=None, raise_on_error=True, missing='none', **kwargs)¶
Retrieve multiple document by their
id
s. Returns a list of instances in the same order as requested.- Parameters
docs – list of
id
s of the documents to be retrieved or a list of document specifications as per https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.htmlindex – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
missing – what to do when one of the documents requested is not found. Valid options are
'none'
(useNone
),'raise'
(raiseNotFoundError
) or'skip'
(ignore the missing document).
Any additional keyword arguments will be passed to
Elasticsearch.mget
unchanged.
- save(using=None, index=None, validate=True, skip_empty=True, **kwargs)¶
Save the document into elasticsearch. If the document doesn’t exist it is created, it is overwritten otherwise. Returns
True
if this operations resulted in new document being created.- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
validate – set to
False
to skip validating the documentskip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
Any additional keyword arguments will be passed to
Elasticsearch.index
unchanged.:return operation result created/updated
- classmethod search(using=None, index=None)¶
Create an
Search
instance that will search over thisDocument
.
- to_dict(include_meta=False, skip_empty=True)¶
Serialize the instance into a dictionary so that it can be saved in elasticsearch.
- Parameters
include_meta – if set to
True
will include all the metadata (_index
,_id
etc). Otherwise just the document’s data is serialized. This is useful when passing multiple instances intoelasticsearch.helpers.bulk
.skip_empty – if set to
False
will cause empty values (None
,[]
,{}
) to be left on the document. Those values will be stripped out otherwise as they make no difference in elasticsearch.
- update(using=None, index=None, detect_noop=True, doc_as_upsert=False, refresh=False, retry_on_conflict=None, script=None, script_id=None, scripted_upsert=False, upsert=None, **fields)¶
Partial update of the document, specify fields you wish to update and both the instance and the document in elasticsearch will be updated:
doc = MyDocument(title='Document Title!') doc.save() doc.update(title='New Document Title!')
- Parameters
index – elasticsearch index to use, if the
Document
is associated with an index this can be omitted.using – connection alias to use, defaults to
'default'
detect_noop – Set to
False
to disable noop detection.refresh – Control when the changes made by this request are visible to search. Set to
True
for immediate effect.retry_on_conflict – In between the get and indexing phases of the update, it is possible that another process might have already updated the same document. By default, the update will fail with a version conflict exception. The retry_on_conflict parameter controls how many times to retry the update before finally throwing an exception.
doc_as_upsert – Instead of sending a partial doc plus an upsert doc, setting doc_as_upsert to true will use the contents of doc as the upsert value
:return operation result noop/updated
Lib¶
- lib.http.HTTP_Status¶
alias of
HTTPStatus
Response¶
Reader¶
Resource¶
Agent¶
- class resource.agent.catalog.Agent_Catalog_Resource[source]¶
- doc¶
alias of
Agent_Catalog_Document
- on_delete(req, resp, id=None)¶
Delete agent catalogs filtered by the query in the request body. — summary: Agent catalog Delete (Multiple). description: Delete agent catalogs filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [agent-catalog] responses:
- 205:
description: All Agent catalogs correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Agent catalogs based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete one or more agent catalogs based on the request query. schema:
type: array items :
- oneOf:
Reset_Content_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the list of agent catalogs filtered by the query in the request body. — summary: agent catalog Read (Multiple). description: Get the list of agent catalogs filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [agent-catalog] responses:
- 200:
description: List of agent catalogs filtered by the query in the request body. schema:
type: array items: Agent_Catalog_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Agent catalog based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get agent catalogs with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create new agent catalogs. — summary: Agent catalog Creation (Multiple) description: Create new agent catalogs. parameters:
name: payload required: true in: body schema:
type: array items: Agent_Catalog_Schema
tags: [agent-catalog] responses:
- 201:
description: Agent catalog correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create agent catalogs based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create ore or more agent catalogs based on the request. schema:
type: array items :
- oneOf:
Created_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update agent catalogs. — summary: Agent catalog Update (Multiple). description: Update agent catalogs. parameters:
name: payload required: true in: body schema:
type: array items: Agent_Catalog_Schema
tags: [agent-catalog] responses:
- 200:
description: All Agent catalogs correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update agent catalogs based on the request. schema: No_Content_Response_Schema
- 304:
description: Update for one or more agent catalogs not necessary. schema:
type: array items:
- oneOf:
Ok_Response_Schema
Not_Modified_Response
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update one or more agent catalogs based on the request. schema:
type: array items :
- oneOf:
Ok_Response_Schema
Not_Modified_Response
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Agent_Catalog_Schema
- class resource.agent.catalog.Agent_Catalog_Selected_Resource[source]¶
- doc¶
alias of
Agent_Catalog_Document
- on_delete(req, resp, id=None)¶
Delete the agent catalog with the given id and filtered by the query in the request body. — summary: Agent catalog Delete (Single). description: Delete the agent catalog with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [agent-catalog] responses:
- 205:
description: Agent catalog with the given id correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Agent catalog with the given id and based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete the agent catalog with the given id and based on the request query. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the agent catalog with the given id and filtered by the query in the request body. — summary: Agent catalog Read (Single). description: Get the agent catalog with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [agent-catalog] responses:
- 200:
description: Agent catalog with the given id and filtered by the query in the request body. schema:
type: array items: Agent_Catalog_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Agent catalog based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get agent catalogs with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create a new agent catalog with the given id. — summary: Agent catalog Create (Single). description: Create a new agent catalog with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Agent_Catalog_Schema
tags: [agent-catalog] responses:
- 201:
description: Agent catalog with the given id correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create the agent catalog with the given id and based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create the agent catalog with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update the agent catalog with the given id. — summary: Agent catalog Update (Single). description: Update the agent catalog with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Agent_Catalog_Schema
tags: [agent-catalog] responses:
- 200:
description: Agent catalog with the given id correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update agent catalogs with the given id and based on the request. schema: No_Content_Response_Schema
- 304:
description: Update of the agent catalog with the given id not necessary. schema:
type: array items: Not_Modified_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update the agent catalog with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Agent_Catalog_Schema
- class resource.agent.instance.Agent_Instance_Resource[source]¶
- doc¶
alias of
Agent_Instance_Document
- on_delete(req, resp, id=None)¶
Delete agent instances filtered by the query in the request body. — summary: Agent instance Delete (Multiple). description: Delete agent instances filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [agent-instance] responses:
- 205:
description: All Agent instances correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Agent instances based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete one or more agent instances based on the request query. schema:
type: array items :
- oneOf:
Reset_Content_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the list of agent instances filtered by the query in the request body. — summary: agent instance Read (Multiple). description: Get the list of agent instances filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [agent-instance] responses:
- 200:
description: List of agent instances filtered by the query in the request body. schema:
type: array items: Agent_Instance_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Agent instance based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get agent instances with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create new agent instances. — summary: Agent instance Creation (Multiple) description: Create new agent instances. parameters:
name: payload required: true in: body schema:
type: array items: Agent_Instance_Schema
tags: [agent-instance] responses:
- 201:
description: Agent instance correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create agent instances based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create ore or more agent instances based on the request. schema:
type: array items :
- oneOf:
Created_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update agent instances. — summary: Agent instance Update (Multiple). description: Update agent instances. parameters:
name: payload required: true in: body schema:
type: array items: Agent_Instance_Schema
tags: [agent-instance] responses:
- 200:
description: All Agent instances correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update agent instances based on the request. schema: No_Content_Response_Schema
- 304:
description: Update for one or more agent instances not necessary. schema:
type: array items:
- oneOf:
Ok_Response_Schema
Not_Modified_Response
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update one or more agent instances based on the request. schema:
type: array items :
- oneOf:
Ok_Response_Schema
Not_Modified_Response
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Agent_Instance_Schema
- class resource.agent.instance.Agent_Instance_Selected_Resource[source]¶
- doc¶
alias of
Agent_Instance_Document
- on_delete(req, resp, id=None)¶
Delete the agent instance with the given id and filtered by the query in the request body. — summary: Agent instance Delete (Single). description: Delete the agent instance with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [agent-instance] responses:
- 205:
description: Agent instance with the given id correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Agent instance with the given id and based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete the agent instance with the given id and based on the request query. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the agent instance with the given id and filtered by the query in the request body. — summary: Agent instance Read (Single). description: Get the agent instance with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [agent-instance] responses:
- 200:
description: Agent instance with the given id and filtered by the query in the request body. schema:
type: array items: Agent_Instance_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Agent instance based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get agent instances with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create a new agent instance with the given id. — summary: Agent instance Create (Single). description: Create a new agent instance with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Agent_Instance_Schema
tags: [agent-instance] responses:
- 201:
description: Agent instance with the given id correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create the agent instance with the given id and based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create the agent instance with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update the agent instance with the given id. — summary: Agent instance Update (Single). description: Update the agent instance with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Agent_Instance_Schema
tags: [agent-instance] responses:
- 200:
description: Agent instance with the given id correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update agent instances with the given id and based on the request. schema: No_Content_Response_Schema
- 304:
description: Update of the agent instance with the given id not necessary. schema:
type: array items: Not_Modified_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update the agent instance with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Agent_Instance_Schema
eBPF Program¶
- class resource.ebpf_program.catalog.eBPF_Program_Catalog_Resource[source]¶
- doc¶
alias of
eBPF_Program_Catalog_Document
- on_delete(req, resp, id=None)¶
Delete eBPF program catalogs filtered by the query in the request body. — summary: Ebpf program catalog Delete (Multiple). description: Delete eBPF program catalogs filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [ebpf-program-catalog] responses:
- 205:
description: All Ebpf program catalogs correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Ebpf program catalogs based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete one or more eBPF program catalogs based on the request query. schema:
type: array items :
- oneOf:
Reset_Content_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the list of eBPF program catalogs filtered by the query in the request body. — summary: eBPF program catalog Read (Multiple). description: Get the list of eBPF program catalogs filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [ebpf-program-catalog] responses:
- 200:
description: List of eBPF program catalogs filtered by the query in the request body. schema:
type: array items: eBPF_Program_Catalog_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Ebpf program catalog based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get eBPF program catalogs with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create new eBPF program catalogs. — summary: Ebpf program catalog Creation (Multiple) description: Create new eBPF program catalogs. parameters:
name: payload required: true in: body schema:
type: array items: eBPF_Program_Catalog_Schema
tags: [ebpf-program-catalog] responses:
- 201:
description: Ebpf program catalog correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create eBPF program catalogs based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create ore or more eBPF program catalogs based on the request. schema:
type: array items :
- oneOf:
Created_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update eBPF program catalogs. — summary: Ebpf program catalog Update (Multiple). description: Update eBPF program catalogs. parameters:
name: payload required: true in: body schema:
type: array items: eBPF_Program_Catalog_Schema
tags: [ebpf-program-catalog] responses:
- 200:
description: All Ebpf program catalogs correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update eBPF program catalogs based on the request. schema: No_Content_Response_Schema
- 304:
description: Update for one or more eBPF program catalogs not necessary. schema:
type: array items:
- oneOf:
Ok_Response_Schema
Not_Modified_Response
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update one or more eBPF program catalogs based on the request. schema:
type: array items :
- oneOf:
Ok_Response_Schema
Not_Modified_Response
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
eBPF_Program_Catalog_Schema
- class resource.ebpf_program.catalog.eBPF_Program_Catalog_Selected_Resource[source]¶
- doc¶
alias of
eBPF_Program_Catalog_Document
- on_delete(req, resp, id=None)¶
Delete the eBPF program catalog with the given id and filtered by the query in the request body. — summary: Ebpf program catalog Delete (Single). description: Delete the eBPF program catalog with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [ebpf-program-catalog] responses:
- 205:
description: Ebpf program catalog with the given id correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Ebpf program catalog with the given id and based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete the eBPF program catalog with the given id and based on the request query. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the eBPF program catalog with the given id and filtered by the query in the request body. — summary: Ebpf program catalog Read (Single). description: Get the eBPF program catalog with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [ebpf-program-catalog] responses:
- 200:
description: Ebpf program catalog with the given id and filtered by the query in the request body. schema:
type: array items: eBPF_Program_Catalog_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Ebpf program catalog based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get eBPF program catalogs with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create a new eBPF program catalog with the given id. — summary: Ebpf program catalog Create (Single). description: Create a new eBPF program catalog with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: eBPF_Program_Catalog_Schema
tags: [ebpf-program-catalog] responses:
- 201:
description: Ebpf program catalog with the given id correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create the eBPF program catalog with the given id and based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create the eBPF program catalog with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update the eBPF program catalog with the given id. — summary: Ebpf program catalog Update (Single). description: Update the eBPF program catalog with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: eBPF_Program_Catalog_Schema
tags: [ebpf-program-catalog] responses:
- 200:
description: Ebpf program catalog with the given id correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update eBPF program catalogs with the given id and based on the request. schema: No_Content_Response_Schema
- 304:
description: Update of the eBPF program catalog with the given id not necessary. schema:
type: array items: Not_Modified_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update the eBPF program catalog with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
eBPF_Program_Catalog_Schema
- class resource.ebpf_program.instance.eBPF_Program_Instance_Resource[source]¶
- doc¶
alias of
eBPF_Program_Instance_Document
- on_delete(req, resp, id=None)¶
Delete eBPF programs filtered by the query in the request body. — summary: Ebpf program Delete (Multiple). description: Delete eBPF programs filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [ebpf-program-instance] responses:
- 205:
description: All Ebpf programs correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Ebpf programs based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete one or more eBPF programs based on the request query. schema:
type: array items :
- oneOf:
Reset_Content_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the list of eBPF programs filtered by the query in the request body. — summary: eBPF program Read (Multiple). description: Get the list of eBPF programs filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [ebpf-program-instance] responses:
- 200:
description: List of eBPF programs filtered by the query in the request body. schema:
type: array items: eBPF_Program_Instance_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Ebpf program based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get eBPF programs with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create new eBPF programs. — summary: Ebpf program Creation (Multiple) description: Create new eBPF programs. parameters:
name: payload required: true in: body schema:
type: array items: eBPF_Program_Instance_Schema
tags: [ebpf-program-instance] responses:
- 201:
description: Ebpf program correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create eBPF programs based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create ore or more eBPF programs based on the request. schema:
type: array items :
- oneOf:
Created_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update eBPF programs. — summary: Ebpf program Update (Multiple). description: Update eBPF programs. parameters:
name: payload required: true in: body schema:
type: array items: eBPF_Program_Instance_Schema
tags: [ebpf-program-instance] responses:
- 200:
description: All Ebpf programs correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update eBPF programs based on the request. schema: No_Content_Response_Schema
- 304:
description: Update for one or more eBPF programs not necessary. schema:
type: array items:
- oneOf:
Ok_Response_Schema
Not_Modified_Response
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update one or more eBPF programs based on the request. schema:
type: array items :
- oneOf:
Ok_Response_Schema
Not_Modified_Response
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
eBPF_Program_Instance_Schema
- class resource.ebpf_program.instance.eBPF_Program_Instance_Selected_Resource[source]¶
- doc¶
alias of
eBPF_Program_Instance_Document
- on_delete(req, resp, id=None)¶
Delete the eBPF program with the given id and filtered by the query in the request body. — summary: Ebpf program Delete (Single). description: Delete the eBPF program with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [ebpf-program-instance] responses:
- 205:
description: Ebpf program with the given id correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Ebpf program with the given id and based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete the eBPF program with the given id and based on the request query. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the eBPF program with the given id and filtered by the query in the request body. — summary: Ebpf program Read (Single). description: Get the eBPF program with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [ebpf-program-instance] responses:
- 200:
description: Ebpf program with the given id and filtered by the query in the request body. schema:
type: array items: eBPF_Program_Instance_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Ebpf program based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get eBPF programs with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create a new eBPF program with the given id. — summary: Ebpf program Create (Single). description: Create a new eBPF program with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: eBPF_Program_Instance_Schema
tags: [ebpf-program-instance] responses:
- 201:
description: Ebpf program with the given id correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create the eBPF program with the given id and based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create the eBPF program with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update the eBPF program with the given id. — summary: Ebpf program Update (Single). description: Update the eBPF program with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: eBPF_Program_Instance_Schema
tags: [ebpf-program-instance] responses:
- 200:
description: Ebpf program with the given id correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update eBPF programs with the given id and based on the request. schema: No_Content_Response_Schema
- 304:
description: Update of the eBPF program with the given id not necessary. schema:
type: array items: Not_Modified_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update the eBPF program with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
eBPF_Program_Instance_Schema
Execution Environment¶
- class resource.exec_env.Exec_Env_Resource[source]¶
- doc¶
alias of
Exec_Env_Document
- on_delete(req, resp, id=None)¶
Delete execution environments filtered by the query in the request body. — summary: Execution environment Delete (Multiple). description: Delete execution environments filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [exec-env] responses:
- 205:
description: All Execution environments correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Execution environments based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete one or more execution environments based on the request query. schema:
type: array items :
- oneOf:
Reset_Content_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the list of execution environments filtered by the query in the request body. — summary: execution environment Read (Multiple). description: Get the list of execution environments filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [exec-env] responses:
- 200:
description: List of execution environments filtered by the query in the request body. schema:
type: array items: Exec_Env_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Execution environment based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get execution environments with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create new execution environments. — summary: Execution environment Creation (Multiple) description: Create new execution environments. parameters:
name: payload required: true in: body schema:
type: array items: Exec_Env_Schema
tags: [exec-env] responses:
- 201:
description: Execution environment correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create execution environments based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create ore or more execution environments based on the request. schema:
type: array items :
- oneOf:
Created_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update execution environments. — summary: Execution environment Update (Multiple). description: Update execution environments. parameters:
name: payload required: true in: body schema:
type: array items: Exec_Env_Schema
tags: [exec-env] responses:
- 200:
description: All Execution environments correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update execution environments based on the request. schema: No_Content_Response_Schema
- 304:
description: Update for one or more execution environments not necessary. schema:
type: array items:
- oneOf:
Ok_Response_Schema
Not_Modified_Response
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update one or more execution environments based on the request. schema:
type: array items :
- oneOf:
Ok_Response_Schema
Not_Modified_Response
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Exec_Env_Schema
- class resource.exec_env.Exec_Env_Selected_Resource[source]¶
- doc¶
alias of
Exec_Env_Document
- on_delete(req, resp, id=None)¶
Delete the execution environment with the given id and filtered by the query in the request body. — summary: Execution environment Delete (Single). description: Delete the execution environment with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [exec-env] responses:
- 205:
description: Execution environment with the given id correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Execution environment with the given id and based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete the execution environment with the given id and based on the request query. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the execution environment with the given id and filtered by the query in the request body. — summary: Execution environment Read (Single). description: Get the execution environment with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [exec-env] responses:
- 200:
description: Execution environment with the given id and filtered by the query in the request body. schema:
type: array items: Exec_Env_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Execution environment based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get execution environments with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create a new execution environment with the given id. — summary: Execution environment Create (Single). description: Create a new execution environment with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Exec_Env_Schema
tags: [exec-env] responses:
- 201:
description: Execution environment with the given id correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create the execution environment with the given id and based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create the execution environment with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update the execution environment with the given id. — summary: Execution environment Update (Single). description: Update the execution environment with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Exec_Env_Schema
tags: [exec-env] responses:
- 200:
description: Execution environment with the given id correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update execution environments with the given id and based on the request. schema: No_Content_Response_Schema
- 304:
description: Update of the execution environment with the given id not necessary. schema:
type: array items: Not_Modified_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update the execution environment with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Exec_Env_Schema
- class resource.exec_env.Exec_Env_Type_Resource[source]¶
- doc¶
alias of
Exec_Env_Type_Document
- on_delete(req, resp, id=None)¶
Delete execution environment types filtered by the query in the request body. — summary: Execution environment type Delete (Multiple). description: Delete execution environment types filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [exec-env-type] responses:
- 205:
description: All Execution environment types correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Execution environment types based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete one or more execution environment types based on the request query. schema:
type: array items :
- oneOf:
Reset_Content_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the list of execution environment types filtered by the query in the request body. — summary: execution environment type Read (Multiple). description: Get the list of execution environment types filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [exec-env-type] responses:
- 200:
description: List of execution environment types filtered by the query in the request body. schema:
type: array items: Exec_Env_Type_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Execution environment type based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get execution environment types with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create new execution environment types. — summary: Execution environment type Creation (Multiple) description: Create new execution environment types. parameters:
name: payload required: true in: body schema:
type: array items: Exec_Env_Type_Schema
tags: [exec-env-type] responses:
- 201:
description: Execution environment type correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create execution environment types based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create ore or more execution environment types based on the request. schema:
type: array items :
- oneOf:
Created_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update execution environment types. — summary: Execution environment type Update (Multiple). description: Update execution environment types. parameters:
name: payload required: true in: body schema:
type: array items: Exec_Env_Type_Schema
tags: [exec-env-type] responses:
- 200:
description: All Execution environment types correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update execution environment types based on the request. schema: No_Content_Response_Schema
- 304:
description: Update for one or more execution environment types not necessary. schema:
type: array items:
- oneOf:
Ok_Response_Schema
Not_Modified_Response
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update one or more execution environment types based on the request. schema:
type: array items :
- oneOf:
Ok_Response_Schema
Not_Modified_Response
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Exec_Env_Type_Schema
- class resource.exec_env.Exec_Env_Type_Selected_Resource[source]¶
- doc¶
alias of
Exec_Env_Type_Document
- on_delete(req, resp, id=None)¶
Delete the execution environment type with the given id and filtered by the query in the request body. — summary: Execution environment type Delete (Single). description: Delete the execution environment type with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [exec-env-type] responses:
- 205:
description: Execution environment type with the given id correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Execution environment type with the given id and based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete the execution environment type with the given id and based on the request query. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the execution environment type with the given id and filtered by the query in the request body. — summary: Execution environment type Read (Single). description: Get the execution environment type with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [exec-env-type] responses:
- 200:
description: Execution environment type with the given id and filtered by the query in the request body. schema:
type: array items: Exec_Env_Type_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Execution environment type based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get execution environment types with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create a new execution environment type with the given id. — summary: Execution environment type Create (Single). description: Create a new execution environment type with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Exec_Env_Type_Schema
tags: [exec-env-type] responses:
- 201:
description: Execution environment type with the given id correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create the execution environment type with the given id and based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create the execution environment type with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update the execution environment type with the given id. — summary: Execution environment type Update (Single). description: Update the execution environment type with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Exec_Env_Type_Schema
tags: [exec-env-type] responses:
- 200:
description: Execution environment type with the given id correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update execution environment types with the given id and based on the request. schema: No_Content_Response_Schema
- 304:
description: Update of the execution environment type with the given id not necessary. schema:
type: array items: Not_Modified_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update the execution environment type with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Exec_Env_Type_Schema
Network Link¶
- class resource.network_link.Network_Link_Resource[source]¶
- doc¶
alias of
Network_Link_Document
- on_delete(req, resp, id=None)¶
Delete network links filtered by the query in the request body. — summary: Network link Delete (Multiple). description: Delete network links filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [network-link] responses:
- 205:
description: All Network links correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Network links based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete one or more network links based on the request query. schema:
type: array items :
- oneOf:
Reset_Content_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the list of network links filtered by the query in the request body. — summary: network link Read (Multiple). description: Get the list of network links filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [network-link] responses:
- 200:
description: List of network links filtered by the query in the request body. schema:
type: array items: Network_Link_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Network link based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get network links with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create new network links. — summary: Network link Creation (Multiple) description: Create new network links. parameters:
name: payload required: true in: body schema:
type: array items: Network_Link_Schema
tags: [network-link] responses:
- 201:
description: Network link correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create network links based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create ore or more network links based on the request. schema:
type: array items :
- oneOf:
Created_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update network links. — summary: Network link Update (Multiple). description: Update network links. parameters:
name: payload required: true in: body schema:
type: array items: Network_Link_Schema
tags: [network-link] responses:
- 200:
description: All Network links correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update network links based on the request. schema: No_Content_Response_Schema
- 304:
description: Update for one or more network links not necessary. schema:
type: array items:
- oneOf:
Ok_Response_Schema
Not_Modified_Response
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update one or more network links based on the request. schema:
type: array items :
- oneOf:
Ok_Response_Schema
Not_Modified_Response
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Network_Link_Schema
- class resource.network_link.Network_Link_Selected_Resource[source]¶
- doc¶
alias of
Network_Link_Document
- on_delete(req, resp, id=None)¶
Delete the network link with the given id and filtered by the query in the request body. — summary: Network link Delete (Single). description: Delete the network link with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [network-link] responses:
- 205:
description: Network link with the given id correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Network link with the given id and based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete the network link with the given id and based on the request query. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the network link with the given id and filtered by the query in the request body. — summary: Network link Read (Single). description: Get the network link with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [network-link] responses:
- 200:
description: Network link with the given id and filtered by the query in the request body. schema:
type: array items: Network_Link_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Network link based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get network links with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create a new network link with the given id. — summary: Network link Create (Single). description: Create a new network link with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Network_Link_Schema
tags: [network-link] responses:
- 201:
description: Network link with the given id correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create the network link with the given id and based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create the network link with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update the network link with the given id. — summary: Network link Update (Single). description: Update the network link with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Network_Link_Schema
tags: [network-link] responses:
- 200:
description: Network link with the given id correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update network links with the given id and based on the request. schema: No_Content_Response_Schema
- 304:
description: Update of the network link with the given id not necessary. schema:
type: array items: Not_Modified_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update the network link with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Network_Link_Schema
- class resource.network_link.Network_Link_Type_Resource[source]¶
- doc¶
alias of
Network_Link_Type_Document
- on_delete(req, resp, id=None)¶
Delete network link types filtered by the query in the request body. — summary: Network link type Delete (Multiple). description: Delete network link types filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [network-link-type] responses:
- 205:
description: All Network link types correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Network link types based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete one or more network link types based on the request query. schema:
type: array items :
- oneOf:
Reset_Content_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the list of network link types filtered by the query in the request body. — summary: network link type Read (Multiple). description: Get the list of network link types filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [network-link-type] responses:
- 200:
description: List of network link types filtered by the query in the request body. schema:
type: array items: Network_Link_Type_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Network link type based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get network link types with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create new network link types. — summary: Network link type Creation (Multiple) description: Create new network link types. parameters:
name: payload required: true in: body schema:
type: array items: Network_Link_Type_Schema
tags: [network-link-type] responses:
- 201:
description: Network link type correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create network link types based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create ore or more network link types based on the request. schema:
type: array items :
- oneOf:
Created_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update network link types. — summary: Network link type Update (Multiple). description: Update network link types. parameters:
name: payload required: true in: body schema:
type: array items: Network_Link_Type_Schema
tags: [network-link-type] responses:
- 200:
description: All Network link types correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update network link types based on the request. schema: No_Content_Response_Schema
- 304:
description: Update for one or more network link types not necessary. schema:
type: array items:
- oneOf:
Ok_Response_Schema
Not_Modified_Response
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update one or more network link types based on the request. schema:
type: array items :
- oneOf:
Ok_Response_Schema
Not_Modified_Response
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Network_Link_Type_Schema
- class resource.network_link.Network_Link_Type_Selected_Resource[source]¶
- doc¶
alias of
Network_Link_Type_Document
- on_delete(req, resp, id=None)¶
Delete the network link type with the given id and filtered by the query in the request body. — summary: Network link type Delete (Single). description: Delete the network link type with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [network-link-type] responses:
- 205:
description: Network link type with the given id correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Network link type with the given id and based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete the network link type with the given id and based on the request query. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the network link type with the given id and filtered by the query in the request body. — summary: Network link type Read (Single). description: Get the network link type with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [network-link-type] responses:
- 200:
description: Network link type with the given id and filtered by the query in the request body. schema:
type: array items: Network_Link_Type_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Network link type based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get network link types with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create a new network link type with the given id. — summary: Network link type Create (Single). description: Create a new network link type with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Network_Link_Type_Schema
tags: [network-link-type] responses:
- 201:
description: Network link type with the given id correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create the network link type with the given id and based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create the network link type with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update the network link type with the given id. — summary: Network link type Update (Single). description: Update the network link type with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Network_Link_Type_Schema
tags: [network-link-type] responses:
- 200:
description: Network link type with the given id correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update network link types with the given id and based on the request. schema: No_Content_Response_Schema
- 304:
description: Update of the network link type with the given id not necessary. schema:
type: array items: Not_Modified_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update the network link type with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Network_Link_Type_Schema
Connection¶
- class resource.connection.Connection_Resource[source]¶
- doc¶
alias of
Connection_Document
- on_delete(req, resp, id=None)¶
Delete connections filtered by the query in the request body. — summary: Connection Delete (Multiple). description: Delete connections filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [connection] responses:
- 205:
description: All Connections correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Connections based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete one or more connections based on the request query. schema:
type: array items :
- oneOf:
Reset_Content_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the list of connections filtered by the query in the request body. — summary: connection Read (Multiple). description: Get the list of connections filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [connection] responses:
- 200:
description: List of connections filtered by the query in the request body. schema:
type: array items: Connection_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Connection based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get connections with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create new connections. — summary: Connection Creation (Multiple) description: Create new connections. parameters:
name: payload required: true in: body schema:
type: array items: Connection_Schema
tags: [connection] responses:
- 201:
description: Connection correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create connections based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create ore or more connections based on the request. schema:
type: array items :
- oneOf:
Created_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update connections. — summary: Connection Update (Multiple). description: Update connections. parameters:
name: payload required: true in: body schema:
type: array items: Connection_Schema
tags: [connection] responses:
- 200:
description: All Connections correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update connections based on the request. schema: No_Content_Response_Schema
- 304:
description: Update for one or more connections not necessary. schema:
type: array items:
- oneOf:
Ok_Response_Schema
Not_Modified_Response
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update one or more connections based on the request. schema:
type: array items :
- oneOf:
Ok_Response_Schema
Not_Modified_Response
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Connection_Schema
- class resource.connection.Connection_Selected_Resource[source]¶
- doc¶
alias of
Connection_Document
- on_delete(req, resp, id=None)¶
Delete the connection with the given id and filtered by the query in the request body. — summary: Connection Delete (Single). description: Delete the connection with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [connection] responses:
- 205:
description: Connection with the given id correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Connection with the given id and based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete the connection with the given id and based on the request query. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the connection with the given id and filtered by the query in the request body. — summary: Connection Read (Single). description: Get the connection with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [connection] responses:
- 200:
description: Connection with the given id and filtered by the query in the request body. schema:
type: array items: Connection_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Connection based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get connections with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create a new connection with the given id. — summary: Connection Create (Single). description: Create a new connection with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Connection_Schema
tags: [connection] responses:
- 201:
description: Connection with the given id correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create the connection with the given id and based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create the connection with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update the connection with the given id. — summary: Connection Update (Single). description: Update the connection with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Connection_Schema
tags: [connection] responses:
- 200:
description: Connection with the given id correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update connections with the given id and based on the request. schema: No_Content_Response_Schema
- 304:
description: Update of the connection with the given id not necessary. schema:
type: array items: Not_Modified_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update the connection with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Connection_Schema
Data¶
- class resource.data.Data_Resource[source]¶
- doc¶
alias of
Data_Document
- on_delete(req, resp, id=None)¶
Delete data filtered by the query in the request body. — summary: Data Delete (Multiple). description: Delete data filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [data] responses:
- 205:
description: All Data correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Data based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete one or more data based on the request query. schema:
type: array items :
- oneOf:
Reset_Content_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the list of data filtered by the query in the request body. — summary: data Read (Multiple). description: Get the list of data filtered by the query in the request body. parameters:
name: payload required: true in: body schema: Query_Request_Schema
tags: [data] responses:
- 200:
description: List of data filtered by the query in the request body. schema:
type: array items: Data_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Data based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get data with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create new data. — summary: Data Creation (Multiple) description: Create new data. parameters:
name: payload required: true in: body schema:
type: array items: Data_Schema
tags: [data] responses:
- 201:
description: Data correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create data based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create ore or more data based on the request. schema:
type: array items :
- oneOf:
Created_Response_Schema
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update data. — summary: Data Update (Multiple). description: Update data. parameters:
name: payload required: true in: body schema:
type: array items: Data_Schema
tags: [data] responses:
- 200:
description: All Data correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update data based on the request. schema: No_Content_Response_Schema
- 304:
description: Update for one or more data not necessary. schema:
type: array items:
- oneOf:
Ok_Response_Schema
Not_Modified_Response
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update one or more data based on the request. schema:
type: array items :
- oneOf:
Ok_Response_Schema
Not_Modified_Response
Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Data_Schema
- class resource.data.Data_Selected_Resource[source]¶
- doc¶
alias of
Data_Document
- on_delete(req, resp, id=None)¶
Delete the data with the given id and filtered by the query in the request body. — summary: Data Delete (Single). description: Delete the data with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [data] responses:
- 205:
description: Data with the given id correctly deleted. schema:
type: array items: Reset_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Data with the given id and based on the request query not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to delete the data with the given id and based on the request query. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_get(req, resp, id=None)¶
Get the data with the given id and filtered by the query in the request body. — summary: Data Read (Single). description: Get the data with the given id and filtered by the query in the request body. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema: Query_Request_Schema
tags: [data] responses:
- 200:
description: Data with the given id and filtered by the query in the request body. schema:
type: array items: Data_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 404:
description: Data based on the request _query_ not found. schema: Not_Found_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to get data with the request _query_. schema: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_post(req, resp, id=None)¶
Create a new data with the given id. — summary: Data Create (Single). description: Create a new data with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Data_Schema
tags: [data] responses:
- 201:
description: Data with the given id correctly created. schema:
type: array items: Created_Response_Schema
- 204:
description: No content to create the data with the given id and based on the request. schema: No_Content_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to create the data with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- on_put(req, resp, id=None)¶
Update the data with the given id. — summary: Data Update (Single). description: Update the data with the given id. parameters:
name: id required: true in: path type: String
name: payload required: true in: body schema:
type: array items: Data_Schema
tags: [data] responses:
- 200:
description: Data with the given id correctly updated. schema:
type: array items: Ok_Response_Schema
- 204:
description: No content to update data with the given id and based on the request. schema: No_Content_Response_Schema
- 304:
description: Update of the data with the given id not necessary. schema:
type: array items: Not_Modified_Response_Schema
- 400:
description: Request not valid. schema: Bad_Request_Response_Schema
- 401:
description: Authentication failed. schema: Unauthorized_Response_Schema
- 406:
description: Request validation failed. schema: Not_Acceptable_Response_Schema
- 415:
description: Media type not supported. schema: Unsupported_Media_Type_Response_Schema
- 422:
description: Not possible to update the data with the given id and based on the request. schema:
type: array items: Unprocessable_Entity_Response_Schema
- 500:
description: Server not available to satisfy the request. schema: Internal_Server_Error_Response_Schema
- schema¶
alias of
Data_Schema
Schema¶
- class schema.base.Base_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)[source]¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
Agent¶
Catalog¶
- class schema.agent.catalog.Agent_Catalog_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Represents an agent in the catalog.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- doc¶
alias of
Agent_Catalog_Document
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.agent.catalog.Agent_Catalog_Action_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
Agent action.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.agent.catalog.Agent_Catalog_Action_Config_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
Agent action configuration.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.agent.catalog.Agent_Catalog_Parameter_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
Agent parameter.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.agent.catalog.Agent_Catalog_Parameter_Config_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
Agent parameter configuration.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.agent.catalog.Agent_Catalog_Resource_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
Agent resource.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.agent.catalog.Agent_Catalog_Resource_Config_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
Agent resource configuration.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
Instance¶
- class schema.agent.instance.Agent_Instance_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Represents an agent instance installed in an execution environment.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- doc¶
alias of
Agent_Instance_Document
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.agent.instance.Agent_Instance_Operation_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Represents the operations to perform with the agent instance installed in an execution environment.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.agent.instance.Agent_Instance_Action_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
Action of the agent instance installed in an execution environment.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.agent.instance.Agent_Instance_Parameter_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
Parameter of the agent instance installed in an execution environment.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.agent.instance.Agent_Instance_Resource_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
Resource of the agent instance installed in an execution environment.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
eBPF Program¶
Catalog¶
- class schema.ebpf_program.catalog.eBPF_Program_Catalog_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Represents an eBPF program in the catalog.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- doc¶
alias of
eBPF_Program_Catalog_Document
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.ebpf_program.catalog.eBPF_Program_Catalog_Parameter_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
eBPF program configuration.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.ebpf_program.catalog.eBPF_Program_Catalog_Config_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
eBPF program configuration.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.ebpf_program.catalog.eBPF_Program_Catalog_Config_Metric_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
eBPF program metric.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.ebpf_program.catalog.eBPF_Program_Catalog_Config_Metric_Open_Metrics_Metadata_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
eBPF program Open Metrics metadata.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.ebpf_program.catalog.eBPF_Program_Catalog_Config_Metric_Open_Metrics_Metadata_Label_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
eBPF program Open Metrics metadata label.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
Instance¶
- class schema.ebpf_program.instance.eBPF_Program_Instance_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Represents an eBPF program instance installed in an execution environment.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- doc¶
alias of
eBPF_Program_Instance_Document
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.ebpf_program.instance.eBPF_Program_Instance_Parameter_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
Parameter of the eBPF program instance installed in an execution environment.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
Execution Environment¶
- class schema.exec_env.LCP_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
Configuration of the LCP running in the execution environment.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.exec_env.Exec_Env_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Represents an execution environment.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- doc¶
alias of
Exec_Env_Document
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.exec_env.Exec_Env_Type_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Represents an execution environment type.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- doc¶
alias of
Exec_Env_Type_Document
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
Network Link¶
- class schema.network_link.Network_Link_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Represents a network link.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- doc¶
alias of
Network_Link_Document
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.network_link.Network_Link_Type_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Represents a network link type.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- doc¶
alias of
Network_Link_Type_Document
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
Connection¶
- class schema.connection.Connection_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Represents an connection between execution environments and network links.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- doc¶
alias of
Connection_Document
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
Data¶
- class schema.data.Data_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Represents the stored data.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- doc¶
alias of
Data_Document
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
Query Request¶
- class schema.query_request.Query_Request_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Query request to filter the items.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.query_request.Query_Request_Order_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Order the filtered items.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.query_request.Query_Request_Limit_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Limit the items to return.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.query_request.Query_Request_Filter_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
For numeric comparison in the clause.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.query_request.Query_Request_Clause_Schema(*args, method=None, check_unique_id=False, **kwargs)[source]¶
Represents a clause to filter a item based on various conditions.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data, response_type=<class 'lib.response.Ok_Response'>, id=None)¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
Response¶
- class schema.response.Exception_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.Base_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
Response for the item creation.
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.Bad_Request_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.Conflict_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.Content_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.Created_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.No_Content_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.Not_Acceptable_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.Not_Found_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.Not_Modified_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.Ok_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.Reset_Content_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.Unauthorized_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.Unprocessable_Entity_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
- class schema.response.Unsupported_Media_Type_Response_Schema(*, only: Optional[Union[Sequence[str], Set[str]]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Optional[Dict] = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: Optional[str] = None)[source]¶
- class Meta¶
Options object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields
: Tuple or list of fields to include in the serialized result.additional
: Tuple or list of fields to include in addition to theexplicitly declared fields.
additional
andfields
are mutually-exclusive options.
include
: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude
: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat
: Default format for Date <fields.Date> fields.datetimeformat
: Default format for DateTime <fields.DateTime> fields.render_module
: Module to use for loads <Schema.loads> and dumps <Schema.dumps>.Defaults to json from the standard library.
ordered
: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors
: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only
: Tuple or list of fields to exclude from serialized results.dump_only
: Tuple or list of fields to exclude from deserializationunknown
: Whether to exclude, include, or raise an error for unknownfields in the data. Use EXCLUDE, INCLUDE or RAISE.
register
: Whether to register the Schema with marshmallow’s internalclass registry. Must be True if you intend to refer to this Schema by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.
- OPTIONS_CLASS¶
alias of
SchemaOpts
- _bind_field(field_name: str, field_obj: Field) None ¶
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name).
Also set field load_only and dump_only values if field_name was specified in
class Meta
.
- static _call_and_store(getter_func, data, *, field_name, error_store, index=None)¶
Call
getter_func
withdata
as its argument, and store any ValidationErrors.- Parameters
getter_func (callable) – Function for getting the serialized/deserialized value from
data
.data – The data passed to
getter_func
.field_name (str) – Field name.
index (int) – Index of the item being validated, if validating a collection, otherwise None.
- _deserialize(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, error_store: ErrorStore, many: bool = False, partial=False, unknown='raise', index=None) Union[_T, List[_T]] ¶
Deserialize
data
.- Parameters
data (dict) – The data to deserialize.
error_store (ErrorStore) – Structure to store errors.
many (bool) – True if
data
should be deserialized as a collection.partial (bool|tuple) – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.
index (int) – Index of the item being serialized (for storing errors) if serializing a collection, otherwise None.
- Returns
A dictionary of the deserialized data.
- _do_load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, postprocess: bool = True)¶
Deserialize data, returning the deserialized result. This method is private API.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to validate required fields. If its value is an iterable, only fields listed in that iterable will be ignored will be allowed missing. If True, all fields will be allowed missing. If None, the value for self.partial is used.
unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
postprocess – Whether to run post_load methods..
- Returns
Deserialized data
- _init_fields() None ¶
Update self.fields, self.load_fields, and self.dump_fields based on schema options. This method is private API.
- _normalize_nested_options() None ¶
Apply then flatten nested schema options. This method is private API.
- _serialize(obj: Union[_T, Iterable[_T]], *, many: bool = False)¶
Serialize
obj
.- Parameters
obj – The object(s) to serialize.
many (bool) – True if
data
should be serialized as a collection.
- Returns
A dictionary of the serialized data
Changed in version 1.0.0: Renamed from
marshal
.
- dump(obj: Any, *, many: Optional[bool] = None)¶
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A dict of serialized data
- Return type
dict
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj: Any, *args, many: Optional[bool] = None, **kwargs)¶
Same as
dump()
, except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many – Whether to serialize obj as a collection. If None, the value for self.many is used.
- Returns
A
json
string- Return type
str
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the serialized data rather than a
(data, errors)
duple. AValidationError
is raised ifobj
is invalid.
- error_messages = {}¶
Overrides for default schema-level error messages
- fields¶
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields: Dict[str, Union[Field, type]], *, name: str = 'GeneratedSchema') type ¶
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
repr
for the class.
New in version 3.0.0.
- get_attribute(obj: Any, attr: str, default: Any)¶
Defines how to pull values from an object to serialize.
New in version 2.0.0.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)¶
Custom error handler function for the schema.
- Parameters
error – The ValidationError raised during (de)serialization.
data – The original input data.
many – Value of
many
on dump or load.partial – Value of
partial
on load.
New in version 2.0.0.
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data: Union[Mapping[str, Any], Iterable[Mapping[str, Any]]], *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None)¶
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters
data – The data to deserialize.
many – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- loads(json_data: str, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None, unknown: Optional[str] = None, **kwargs)¶
Same as
load()
, except it takes a JSON string as input.- Parameters
json_data – A JSON string of the data to deserialize.
many – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.
- Returns
Deserialized data
New in version 1.0.0.
Changed in version 3.0.0b7: This method returns the deserialized data rather than a
(data, errors)
duple. AValidationError
is raised if invalid data are passed.
- on_bind_field(field_name: str, field_obj: Field) None ¶
Hook to modify a field when it is bound to the Schema.
No-op by default.
- validate(data: Mapping, *, many: Optional[bool] = None, partial: Optional[Union[bool, Sequence[str], Set[str]]] = None) Dict[str, List[str]] ¶
Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data – The data to validate.
many – Whether to validate data as a collection. If None, the value for self.many is used.
partial – Whether to ignore missing fields and not require any fields declared. Propagates down to
Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.
- Returns
A dictionary of validation errors.
New in version 1.1.0.
Utils¶
Datetime¶
- utils.datetime.FORMAT = '%Y-%m-%dT%H:%M:%S'¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
Exception¶
JSON¶
Log¶
Sequence¶
Signal¶
String¶
- utils.string.format = <bound method Formatter.format of <utils.string.Formatter object>>¶