[IPython-dev] ANN: numtraits v0.2

Wes Turner wes.turner at gmail.com
Thu Oct 1 09:04:45 EDT 2015

"Numerical properties for Python objects"
https://github.com/astrofrog/numtraits /blob/master/README.md

at first glance, thanks!

other relevant type constraints work:

* https://andreacensi.github.io/contracts/
* http://mypy-lang.org/examples.html

* https://www.python.org/dev/peps/pep-0482/
  PEP 0482 -- Literature Overview for Type Hints
* https://www.python.org/dev/peps/pep-0484/
  PEP 0484 -- Type Hints

other relevant units work:

* https://wrdrd.com/docs/consulting/units#rdf-and-units

scipy pydata ecosystem support:

- how do I save this schema and these units (metadata) with the data? is
this compositional?
- [ ] .meta colspec w/ datatype URIs and unit URIs (pandasrdf#1)
- [ ] ...

looks great; thanks again!
On Oct 1, 2015 7:13 AM, "Thomas Robitaille" <thomas.robitaille at gmail.com>

Hi everyone,

(I sent this to ipython-user but didn't realize it was deprecated, so
re-sending to this list)

We have released a small experimental package called numtraits that
builds on top of the traitlets package and provides a NumericalTrait
class that can be used to validate properties such as:

* number of dimension (for arrays)
* shape (for arrays)
* domain (e.g. positive, negative, range of values)
* units (with support for astropy.units, pint, and quantities)

The idea is to be able to write a class like:

    class Sphere(HasTraits):

        radius = NumericalTrait(domain='strictly-positive', ndim=0)
        position = NumericalTrait(shape=(3,))

and all the validation will then be done automatically when the user
sets 'radius' or 'position'.

In addition, tuples and lists can get automatically converted to
arrays, and default values can be specified. You can read more about
the package and see examples of it in use here:


and it can be easily installed with

  pip install numtraits

The package supports both Python 3.3+ and Legacy Python (2.7) :)

At this point, we would be very interested in feedback - the package
is still very young and we can still change the API if needed. Please
open issues with suggestions!


Tom and Francesco
IPython-dev mailing list
IPython-dev at scipy.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20151001/cc2e32f3/attachment.html>

More information about the IPython-dev mailing list