{"id":15358403,"url":"https://github.com/astrofrog/numtraits","last_synced_at":"2026-03-01T01:01:12.929Z","repository":{"id":57447324,"uuid":"38257122","full_name":"astrofrog/numtraits","owner":"astrofrog","description":"Sanity checking for numerical properties/traits :1234:","archived":false,"fork":false,"pushed_at":"2016-06-21T22:07:36.000Z","size":49,"stargazers_count":38,"open_issues_count":13,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2026-02-12T07:51:16.607Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/astrofrog.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-29T16:08:53.000Z","updated_at":"2025-12-31T04:12:49.000Z","dependencies_parsed_at":"2022-09-03T23:41:51.238Z","dependency_job_id":null,"html_url":"https://github.com/astrofrog/numtraits","commit_stats":null,"previous_names":["astrofrog/numprops"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/astrofrog/numtraits","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astrofrog%2Fnumtraits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astrofrog%2Fnumtraits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astrofrog%2Fnumtraits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astrofrog%2Fnumtraits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/astrofrog","download_url":"https://codeload.github.com/astrofrog/numtraits/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astrofrog%2Fnumtraits/sbom","scorecard":{"id":213610,"data":{"date":"2025-08-11","repo":{"name":"github.com/astrofrog/numtraits","commit":"d0afadc946e9d81d1d5b6c851530899d6b0e1d7c"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.2,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":1,"reason":"Found 2/13 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: BSD 2-Clause \"Simplified\" License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 20 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T01:12:24.486Z","repository_id":57447324,"created_at":"2025-08-17T01:12:24.486Z","updated_at":"2025-08-17T01:12:24.486Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29957128,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T22:53:01.873Z","status":"ssl_error","status_checked_at":"2026-02-28T22:52:50.699Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T12:41:06.259Z","updated_at":"2026-03-01T01:01:12.877Z","avatar_url":"https://github.com/astrofrog.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Numerical properties for Python objects\n=======================================\n\n[![Travis Build Status](https://travis-ci.org/astrofrog/numtraits.svg?branch=master)](https://travis-ci.org/astrofrog/numtraits) [![Coverage Status](https://coveralls.io/repos/astrofrog/numtraits/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/astrofrog/numtraits?branch=master)\n\n**Please note:** this package is experimental and may still see some changes to the API. If you have any suggestions for improving the API, please open an issue!\n\nAbout\n-----\n\nThis simple module defines a descriptor class that can be used to define\nnumerical properties (scalar and n-dimensional arrays) on classes and provide a\nway to validate these. Thus, instead of writing something like:\n\n```python\nclass Sphere(object):\n\n    @property\n    def radius(self):\n        return self._radius\n\n    @radius.setter\n    def radius(self, value):\n        if value \u003c= 0:\n            raise ValueError(\"Value should be strictly positive\")\n        if not np.isscalar(value):\n            raise TypeError(\"Value should be a scalar\")\n        if not np.isreal(value):\n            raise TypeError(\"Value should be numerical\")\n        self._radius = value\n```\n\nfor each property you want to define, you can simply do:\n\n```python\nfrom numtraits import NumericalTrait\nfrom traitlets import HasTraits\n\nclass Sphere(HasTraits):\n\n    radius = NumericalTrait(domain='strictly-positive', ndim=0)\n```\n\nThe ``NumericalTrait`` class is implemented on top of the [traitlets](https://github.com/ipython/traitlets)\nmodule. Any class using ``NumericalTrait`` for the definition of a property **must** derive from the\n``traitlets.HasTraits`` class.\n\nSupport is also included for checking the dimensionality and shape of arrays\n(which includes converting tuples and lists to arrays on-the-fly), as well as\nchecking the units of quantities for the\n[astropy.units](docs.astropy.org/en/stable/units/),\n[pint](http://pint.readthedocs.org/), and\n[quantities](https://pythonhosted.org/quantities/) unit frameworks.\n\nInstalling\n----------\n\nThis package is compatible with Python 2.7, 3.3 and later, and\nrequires [numpy](http://www.numpy.org) and [traitlets](https://github.com/ipython/traitlets).\nIf you are interested in doing unit validation, you will also need\n[astropy](docs.astropy.org/en/stable/units/),\n[pint](http://pint.readthedocs.org/), or\n[quantities](https://pythonhosted.org/quantities/), depending on which unit\nframework you normally use.\n\nTo install, you can do:\n\n    pip install numtraits\n\nYou can also bundle ``numtraits.py`` into your package if you want to avoid\nusing an external dependency, but please be sure to keep the copyright and the\nlicense in the file.\n\nUsing\n-----\n\nTo create self-validating numerical properties on a class, use the\n``NumericalTrait`` class:\n\n```python\nfrom traitlets import HasTraits\nfrom numtraits import NumericalTrait\n\nclass Sphere(HasTraits):\n\n    radius = NumericalTrait(domain='strictly-positive', ndim=0)\n    position = NumericalTrait(shape=(3,))\n```\n\nWhen a property is set, it will be validated:\n\n```python\n\u003e\u003e\u003e s = Sphere()\n\u003e\u003e\u003e s.radius = 1.\n\u003e\u003e\u003e s.radius = -3\n...\nTraitError: radius should be strictly positive\n\u003e\u003e\u003e s.radius = [1,2]\n...\nTraitError: radius should be a scalar value\n\u003e\u003e\u003e s.position = (1,2,3)\n\u003e\u003e\u003e s.position = 3\n...\nTraitError: position should be a 1-d sequence\n\u003e\u003e\u003e s.position = (1,2,3,4)\n...\nTraitError: position has incorrect length (expected 3 but found 4)\n```\n\nThe following arguments to ``NumericalTrait`` are available:\n\n* ``ndim``: restrict the values to arrays with this number of dimension\n* ``shape``: restrict the values to arrays with this shape. If specified, ``ndim`` does not need to be given.\n* ``domain``: restrict the values to a particular domain - can be one of ``positive``, ``strictly-positive``, ``negative``, ``strictly-negative``, or a tuple representing a range of values.\n* ``default``: the default value to return, if not specified (defaults to ``None``)\n* ``convertible_to``: restrict the values to ones with units that would be convertible to a specific set of units (see section below)\n\nNote that tuples and lists will automatically get converted to Numpy arrays, if they are considered valid.\n\nPhysical units\n--------------\n\nWhile ``NumericalTrait`` can be used for plain scalars and Numpy arrays, it\ncan also be used for scalars and arrays which have associated units, with support for three\npopular unit handling units:\n[astropy.units](docs.astropy.org/en/stable/units/),\n[pint](http://pint.readthedocs.org/), and\n[quantities](https://pythonhosted.org/quantities/).\n\nTo restrict a ``NumericalTrait`` to quantities with a certain type of unit,\nuse the ``convertible_to`` option. This option takes units from any of these\nthree unit packages, and will ensure that any value passed has units equivalent\n(but not necessarily equal) to those specified with the ``convertible_to``\noption.\n\nIf the units passed to ``convertible_to`` are\n[astropy.units](docs.astropy.org/en/stable/units/) units, then any value passed\nto the property should then be an\n[astropy.units](docs.astropy.org/en/stable/units/) quantity. If the units\npassed to ``convertible_to`` are [pint](http://pint.readthedocs.org/) units,\nthen any quantity passed to the property should be a\n[pint](http://pint.readthedocs.org/) property. And finally if the units passed\nto ``convertible_to`` are [quantities](https://pythonhosted.org/quantities/)\nunits, then any quantity passed to the property should be a\n[quantities](https://pythonhosted.org/quantities/) quantity.\n\n### astropy.units Quantity example\n\nThe following example shows how to restrict the ``radius`` property to be an\n[astropy.units](docs.astropy.org/en/stable/units/) quantity in units of length:\n\n```python\nfrom astropy import units as u\n\nclass Sphere(HasTraits):\n    radius = NumericalTrait(convertible_to=u.m)\n```\n\nwill then behave as follows:\n\n```python\n\u003e\u003e\u003e s = Sphere()\n\u003e\u003e\u003e s.radius = 3. * u.m\n\u003e\u003e\u003e s.radius = 4. * u.cm\n\u003e\u003e\u003e s.radius = 4. * u.s\n...\nTraitError: radius should be in units convertible to m\n```\n\n### pint Quantity example\n\nThe following example shows how to restrict the ``radius`` property to be a\n[pint](http://pint.readthedocs.org/) quantity in units of length:\n\n```python\nfrom pint import UnitRegistry\nureg = UnitRegistry()\n\nclass Sphere(HasTraits):\n    radius = NumericalTrait(convertible_to=ureg.m)\n```\n\nwill then behave as follows:\n\n```python\n\u003e\u003e\u003e s = Sphere()\n\u003e\u003e\u003e s.radius = 3. * ureg.m\n\u003e\u003e\u003e s.radius = 4. * ureg.cm\n\u003e\u003e\u003e s.radius = 4. * ureg.s\n...\nTraitError: radius should be in units convertible to meter\n```\n\n### quantities Quantity example\n\nFinally, the following example shows how to restrict the ``radius`` property to\nbe a [quantities](https://pythonhosted.org/quantities/) quantity in units of length:\n\n```python\nimport quantities as pq\n\nclass Sphere(HasTraits):\n    radius = NumericalTrait(convertible_to=pq.m)\n```\n\nwill then behave as follows:\n\n```python\n\u003e\u003e\u003e s = Sphere()\n\u003e\u003e\u003e s.radius = 3. * pq.m\n\u003e\u003e\u003e s.radius = 4. * pq.cm\n\u003e\u003e\u003e s.radius = 4. * pq.s\n...\nTraitError: radius should be in units convertible to m\n```\n\nPlanned support\n---------------\n\n* Linking of properties (e.g. a property should have the same dimensions as another)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastrofrog%2Fnumtraits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fastrofrog%2Fnumtraits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastrofrog%2Fnumtraits/lists"}