Skip to main content

Serializable schema using traits

Project description


.. image::

.. image::
:alt: Documentation Status

.. image::

.. image::

Create serializable, type-checked schema using traits_ and Numpy. A typical use
case involves saving several Numpy arrays of varying shape and type.

.. _traits:

Defining schema

.. note::

The following assumes a basic familiarity with the ``traits`` package. See
its `documentation <>`_ for details.

In order to be able to properly serialize data, non-scalar traits should be
declared as a ``traits.api.Array`` type. Example:

.. code-block:: python

import numpy as np
from traits.api import Array, String
from traitschema import Schema

class NamedMatrix(Schema):
name = String()
data = Array(dtype=np.float64)

matrix = NamedMatrix(name="name", data=np.random.random((8, 8)))

For other demos, see the ``demos`` directory.

Saving and loading

Data can be stored in the following formats:

* HDF5 via ``h5py``
* JSON via the standard library ``json`` module
* Numpy ``npz`` format

Multiple schema can be saved at once to a zip file via
:func:`traitschema.bundle_schema` and loaded with

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Built Distribution

traitschema-1.2.0-py2.py3-none-any.whl (8.8 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page