{"id":18295858,"url":"https://github.com/astropenguin/dataspecs","last_synced_at":"2025-04-05T12:31:46.172Z","repository":{"id":195553286,"uuid":"693110693","full_name":"astropenguin/dataspecs","owner":"astropenguin","description":"Data specifications by data classes","archived":false,"fork":false,"pushed_at":"2025-03-25T12:23:08.000Z","size":1750,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T12:26:35.524Z","etag":null,"topics":["dataclasses","python","specifications","typing"],"latest_commit_sha":null,"homepage":"https://astropenguin.github.io/dataspecs/v4.0.0","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/astropenguin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-18T11:21:49.000Z","updated_at":"2025-01-17T02:05:51.000Z","dependencies_parsed_at":"2024-02-29T18:28:20.594Z","dependency_job_id":"0f45db31-b26e-49b9-bf0e-9696bef49c60","html_url":"https://github.com/astropenguin/dataspecs","commit_stats":null,"previous_names":["astropenguin/dataspecs"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astropenguin%2Fdataspecs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astropenguin%2Fdataspecs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astropenguin%2Fdataspecs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astropenguin%2Fdataspecs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/astropenguin","download_url":"https://codeload.github.com/astropenguin/dataspecs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247338971,"owners_count":20923002,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["dataclasses","python","specifications","typing"],"created_at":"2024-11-05T14:38:33.528Z","updated_at":"2025-04-05T12:31:41.161Z","avatar_url":"https://github.com/astropenguin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dataspecs\n\n[![Release](https://img.shields.io/pypi/v/dataspecs?label=Release\u0026color=cornflowerblue\u0026style=flat-square)](https://pypi.org/project/dataspecs/)\n[![Python](https://img.shields.io/pypi/pyversions/dataspecs?label=Python\u0026color=cornflowerblue\u0026style=flat-square)](https://pypi.org/project/dataspecs/)\n[![Downloads](https://img.shields.io/pypi/dm/dataspecs?label=Downloads\u0026color=cornflowerblue\u0026style=flat-square)](https://pepy.tech/project/dataspecs)\n[![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.10652375-cornflowerblue?style=flat-square)](https://doi.org/10.5281/zenodo.10652375)\n[![Tests](https://img.shields.io/github/actions/workflow/status/astropenguin/dataspecs/tests.yaml?label=Tests\u0026style=flat-square)](https://github.com/astropenguin/dataspecs/actions)\n\nData specifications by data classes\n\n## Installation\n\n```shell\npip install dataspecs==1.0.1\n```\n\n## Usage\n\n```python\nfrom dataclasses import dataclass\nfrom dataspecs import TagBase, from_dataclass\nfrom enum import auto\nfrom typing import Annotated as Ann\n```\n\n### Simple specifications\n\n```python\nclass Tag(TagBase):\n    ATTR = auto()\n    DATA = auto()\n\n\n@dataclass\nclass Weather:\n    temp: Ann[list[float], Tag.DATA]\n    humid: Ann[list[float], Tag.DATA]\n    location: Ann[str, Tag.ATTR]\n\n\nsimple_specs = from_dataclass(Weather([20.0, 25.0], [50.0, 55.0], \"Tokyo\"))\nsimple_specs\n```\n```python\nSpecs([Spec(id=ID('/temp'), tags=(\u003cTag.DATA: 2\u003e,), type=list[float], data=[20.0, 25.0]),\n       Spec(id=ID('/humid'), tags=(\u003cTag.DATA: 2\u003e,), type=list[float], data=[50.0, 55.0]),\n       Spec(id=ID('/location'), tags=(\u003cTag.ATTR: 1\u003e,), type=\u003cclass 'str'\u003e, data='Tokyo')])\n```\n\n### Nested specifications\n\n```python\nclass Tag(TagBase):\n    ATTR = auto()\n    DATA = auto()\n    DTYPE = auto()\n    NAME = auto()\n    UNITS = auto()\n\n\n@dataclass\nclass Meta:\n    name: Ann[str, Tag.NAME]\n    units: Ann[str, Tag.UNITS]\n\n\n@dataclass\nclass Weather:\n    temp: Ann[list[Ann[float, Tag.DTYPE]], Tag.DATA, Meta(\"Ground temperature\", \"K\")]\n    humid: Ann[list[Ann[float, Tag.DTYPE]], Tag.DATA, Meta(\"Relative humidity\", \"%\")]\n    location: Ann[str, Tag.ATTR]\n\n\nnested_specs = from_dataclass(Weather([20.0, 25.0], [50.0, 55.0], \"Tokyo\"))\nnested_specs\n```\n```python\nSpecs([Spec(id=ID('/temp'), tags=(\u003cTag.DATA: 2\u003e,), type=list[float], data=[20.0, 25.0]),\n       Spec(id=ID('/temp/0'), tags=(\u003cTag.DTYPE: 3\u003e,), type=\u003cclass 'float'\u003e, data=None),\n       Spec(id=ID('/temp/name'), tags=(\u003cTag.NAME: 4\u003e,), type=\u003cclass 'str'\u003e, data='Ground temperature'),\n       Spec(id=ID('/temp/units'), tags=(\u003cTag.UNITS: 5\u003e,), type=\u003cclass 'str'\u003e, data='K'),\n       Spec(id=ID('/humid'), tags=(\u003cTag.DATA: 2\u003e,), type=list[float], data=[50.0, 55.0]),\n       Spec(id=ID('/humid/0'), tags=(\u003cTag.DTYPE: 3\u003e,), type=\u003cclass 'float'\u003e, data=None),\n       Spec(id=ID('/humid/name'), tags=(\u003cTag.NAME: 4\u003e,), type=\u003cclass 'str'\u003e, data='Relative humidity'),\n       Spec(id=ID('/humid/units'), tags=(\u003cTag.UNITS: 5\u003e,), type=\u003cclass 'str'\u003e, data='%'),\n       Spec(id=ID('/location'), tags=(\u003cTag.ATTR: 1\u003e,), type=\u003cclass 'str'\u003e, data='Tokyo')])\n```\n\n### Selecting specifications\n\n```python\nnested_specs[Tag.DATA]\n```\n```python\nSpecs([Spec(id=ID('/temp'), tags=(\u003cTag.DATA: 2\u003e,), type=list[float], data=[20.0, 25.0]),\n       Spec(id=ID('/humid'), tags=(\u003cTag.DATA: 2\u003e,), type=list[float], data=[50.0, 55.0])])\n```\n\n```python\nnested_specs[\"/temp/[a-z]+\"]\n```\n```python\nSpecs([Spec(id=ID('/temp/name'), tags=(\u003cTag.NAME: 4\u003e,), type=\u003cclass 'str'\u003e, data='Ground temperature'),\n       Spec(id=ID('/temp/units'), tags=(\u003cTag.UNITS: 5\u003e,), type=\u003cclass 'str'\u003e, data='K')])\n```\n\n### Grouping specifications\n\n```python\nnested_specs.groups()\n```\n```python\n[Specs([Spec(id=ID('/temp'), tags=(\u003cTag.DATA: 2\u003e,), type=list[float], data=[20.0, 25.0]),\n        Spec(id=ID('/temp/0'), tags=(\u003cTag.DTYPE: 3\u003e,), type=\u003cclass 'float'\u003e, data=None),\n        Spec(id=ID('/temp/name'), tags=(\u003cTag.NAME: 4\u003e,), type=\u003cclass 'str'\u003e, data='Ground temperature'),\n        Spec(id=ID('/temp/units'), tags=(\u003cTag.UNITS: 5\u003e,), type=\u003cclass 'str'\u003e, data='K')]),\n Specs([Spec(id=ID('/humid'), tags=(\u003cTag.DATA: 2\u003e,), type=list[float], data=[50.0, 55.0]),\n        Spec(id=ID('/humid/0'), tags=(\u003cTag.DTYPE: 3\u003e,), type=\u003cclass 'float'\u003e, data=None),\n        Spec(id=ID('/humid/name'), tags=(\u003cTag.NAME: 4\u003e,), type=\u003cclass 'str'\u003e, data='Relative humidity'),\n        Spec(id=ID('/humid/units'), tags=(\u003cTag.UNITS: 5\u003e,), type=\u003cclass 'str'\u003e, data='%')]),\n Specs([Spec(id=ID('/location'), tags=(\u003cTag.ATTR: 1\u003e,), type=\u003cclass 'str'\u003e, data='Tokyo')])]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastropenguin%2Fdataspecs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fastropenguin%2Fdataspecs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastropenguin%2Fdataspecs/lists"}