{"id":37719478,"url":"https://github.com/deniz195/unitdoc","last_synced_at":"2026-01-16T13:31:11.482Z","repository":{"id":65408842,"uuid":"192782983","full_name":"deniz195/unitdoc","owner":"deniz195","description":"A framework that enables classes that describe physical objects with units and easy serialization.","archived":false,"fork":false,"pushed_at":"2021-02-16T09:05:07.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-28T16:32:08.540Z","etag":null,"topics":["attributes","attrs","boilerplate","classes","deserialisation","python","science","serialization","units","yaml"],"latest_commit_sha":null,"homepage":null,"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/deniz195.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2019-06-19T18:16:25.000Z","updated_at":"2020-11-11T13:14:16.000Z","dependencies_parsed_at":"2023-01-22T01:55:10.826Z","dependency_job_id":null,"html_url":"https://github.com/deniz195/unitdoc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/deniz195/unitdoc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deniz195%2Funitdoc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deniz195%2Funitdoc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deniz195%2Funitdoc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deniz195%2Funitdoc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deniz195","download_url":"https://codeload.github.com/deniz195/unitdoc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deniz195%2Funitdoc/sbom","scorecard":{"id":334202,"data":{"date":"2025-08-11","repo":{"name":"github.com/deniz195/unitdoc","commit":"38333ed90c4a3eb57a3342650c7881e6ece6a027"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","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":"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":"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":"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":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"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":"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":"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":"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":"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":"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":"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":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT 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":"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"}}]},"last_synced_at":"2025-08-18T04:19:46.416Z","repository_id":65408842,"created_at":"2025-08-18T04:19:46.417Z","updated_at":"2025-08-18T04:19:46.417Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479033,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: 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":["attributes","attrs","boilerplate","classes","deserialisation","python","science","serialization","units","yaml"],"created_at":"2026-01-16T13:31:10.244Z","updated_at":"2026-01-16T13:31:11.477Z","avatar_url":"https://github.com/deniz195.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unitdoc\r\n![GitHub](https://img.shields.io/github/license/deniz195/unitdoc)\r\n![GitHub Pipenv locked Python version](https://img.shields.io/github/pipenv/locked/python-version/deniz195/unitdoc)\r\n[![PyPI version shields.io](https://img.shields.io/pypi/v/unitdoc?color=green)](https://pypi.python.org/pypi/unitdoc/)\r\n\r\nUnitdoc deals with data objects which describe physical objects, by providing properties with physical units and easy serialization and deserialization. \r\n\r\nLet's look at an example. First, import unitdoc and create the registry that you will use in your application:\r\n\r\n```python\r\nfrom unitdoc import UnitDocRegistry\r\n\r\nudr = UnitDocRegistry()\r\n```\r\n\r\nLet's create a class that represents a battery\r\n```python\r\nimport attr\r\n\r\n@udr.serialize()   \r\n@attr.s()\r\nclass Battery(object):\r\n    name = attr.ib()\r\n\r\n    weight = udr.attrib(default='45g')\r\n    volume = udr.attrib(default='16ml', default_unit='ml')\r\n    capacity = udr.attrib(default='3.0Ah')\r\n    voltage = udr.attrib(default='3.6V', description ='Average voltage')\r\n```\r\n\r\nLet's make a `Battery`\r\n```python\r\na_battery = Battery(name = 'battery', weight='43g')\r\nprint(a_battery)\r\n# outputs: Battery(name='battery', weight=\u003cQuantity(43, 'gram')\u003e, volume=\u003cQuantity(16, 'milliliter')\u003e, capacity=\u003cQuantity(3.0, 'Ah')\u003e, voltage=\u003cQuantity(3.6, 'volt')\u003e)\r\n```\r\n\r\nLet's do interesting calculations: \r\n```python\r\nenergy = (a_battery.capacity * a_battery.voltage).to('Wh')\r\nprint(f'{energy}')\r\n# outputs: 10.8 Wh\r\n```\r\n... and more\r\n```python\r\nenergy_density = (energy / a_battery.weight).to('Wh/kg')\r\nprint(f'{energy} @  {energy_density}')\r\n# outputs: 10.8 Wh @  251.2 Wh / kg\r\n```\r\n\r\nLet's save the battery to a file and reloaded again:\r\n```python\r\nfn = 'a_battery.yaml'\r\n# save to yaml file\r\nwith open(fn, 'w') as f:\r\n    f.write(a_battery.serialize())\r\n\r\n# load from yaml file\r\nwith open(fn, 'r') as f:\r\n    a_loaded_battery = Battery.deserialize(f.read())\r\n\r\nassert a_battery == a_loaded_battery    \r\n```\r\n\r\nIf we look at the `a_battery.yaml` file, we will find:\r\n```yaml\r\nname: battery\r\nweight: !unit 43 g\r\nvolume: !unit 16 ml\r\ncapacity: !unit 3 Ah\r\nvoltage: !unit 3.6 V\r\n```\r\n\r\nThis serialization, we can directly get by\r\n```python\r\n# look at serialized form\r\nprint(a_battery.serialize())\r\n\r\n# outputs:\r\nname: battery\r\nweight: !unit 43 g\r\nvolume: !unit 16 ml\r\ncapacity: !unit 3 Ah\r\nvoltage: !unit 3.6 V\r\n```\r\n\r\nHave fun!\r\n\r\n\r\n## More features\r\nUnitdoc facilitates certain operations, which can improve your code. \r\n\r\nIf you specify `default_unit` in an attribute, quantities are automatically normalized to that unit:\r\n```python\r\na_battery = Battery(name = 'battery', volume='15903 mm^3')\r\nprint(a_battery.volume)\r\n# outputs: 15.9 ml\r\n```\r\n\r\nIf a `default_unit` is specified, any incompatible unit will raise an exception:\r\n```python\r\nfrom unitdoc import DimensionalityError\r\n\r\ntry:\r\n    a_battery = Battery(name = 'battery', volume='42 g')\r\nexcept DimensionalityError as e:\r\n    print(e)\r\n# outputs: Cannot convert from 'gram' ([mass]) to 'milliliter' ([length] ** 3)\r\n```\r\n\r\nYou can retrieve description of parameters, for e.g. data representation code\r\n```python\r\nfrom unitdoc import get_attr_description\r\nprint(get_attr_description(a_battery.__class__, 'voltage'))\r\n# outputs: Average voltage\r\n```\r\n\r\nUnitdoc uses the [attrs library](https://github.com/python-attrs/attrs)), check it out!\r\n\r\n## Installation\r\n\r\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install unitdoc:\r\n\r\n```bash\r\npip install unitdoc\r\n```\r\n\r\nAlternatively, install the latest version from git:\r\n```bash\r\ngit clone https://github.com/deniz195/unitdoc\r\npython unitdoc/setup.py install --user\r\n```\r\n\r\n## Related packages\r\nUnitdoc is based on the following amazing packages:\r\n\r\n- [pint](https://pint.readthedocs.io/) deals with the units\r\n- [ruamel.yamls](https://yaml.readthedocs.io/en/latest/) deals with (de)serializing from semi-structured data (nested dictionaries)\r\n- [attrs](https://github.com/python-attrs/attrs) deals with the boilerplate of data classes\r\n- [cattr](https://github.com/Tinche/cattrs) deals with the unstructuring and restructuring of classes for (de)serialization\r\n\r\nThe UnitDocRegistry creates registries/converters/parsers for each package and aggregates them. You can leverage the features of each package:\r\n\r\nUse unit registry from pint:\r\n```python\r\nq = udr.ureg('1000gram').to('kg')\r\nprint(q)\r\n# outputs: 1 kg\r\n```\r\n\r\nUse yaml parser from ruaml.yaml:\r\n```python\r\nq_yaml = udr.yaml.dump(dict(weight=q))\r\nprint(q_yaml)\r\n# outputs: weight: !unit 1 kg\r\n```\r\n\r\nUse cattr converter:\r\n```python\r\n@udr.serialize()   \r\n@attr.s()\r\nclass Thing(object):\r\n    weight = udr.attrib(default='45g', description ='Total weight')\r\n\r\na_thing = Thing()\r\na_thing_dict = udr.cattr.unstructure(a_thing)\r\n\r\nassert type(a_thing_dict) == dict\r\nprint(a_thing_dict['weight'])\r\n# output: 45 g\r\n```\r\n\r\n## Restrictions\r\nGiven the restrictions of the attrs package, updating attributes safely requires certain precautions. E.g. given the `Battery` class from above the following is possible but not desirable\r\n```python\r\na_battery = Battery(name = 'battery')\r\na_battery.volume = 99\r\ntype(a_battery.volume)\r\n# outputs: int\r\n```\r\nThis is not desirable, because unit check and normalizatin is not performed. \r\n\r\nAn good way to avoid this (and other problems) is to use keyword only (`kw_only=True`) and frozen (`frozen=True`) `attr` objects. \r\n```python\r\n@udr.serialize()   \r\n@attr.s(kw_only=True, frozen=True)\r\nclass BetterBattery(object):\r\n    name = attr.ib()\r\n\r\n    weight = udr.attrib(default='45g')\r\n    volume = udr.attrib(default='16ml', default_unit='ml')\r\n    capacity = udr.attrib(default='3.0Ah')\r\n    voltage = udr.attrib(default='3.6V', description ='Average voltage')\r\n```\r\n\r\nThe keyword only restriction, will not allow the creation of objects from positional parameters, so that the following line fails with a Type error:\r\n```python\r\na_battery = BetterBattery('battery', '42g', '16ml') \r\n```\r\nThis is good, because positional arguments can be dangerous when data model changes over time. The following line creates a new object and is stable if the class changes\r\n```python\r\na_battery = BetterBattery(name='battery', weight='42g', volume='16ml') \r\n```\r\n\r\nThe frozen instance restriction does not allow to mutate an object, so that this line will fail with a `FrozenInstanceError`\r\n```python\r\na_battery.volume = 99 \r\n```\r\nTo update values, you can use the attr.evolve function, which creates a new object with the updated value\r\n```python\r\na_battery = attr.evolve(a_battery, volume='12cm^3')\r\n```\r\nIn this case unit conversion and checks are performed as expected.\r\n\r\nWhile unitdoc works with regular `attr` classes (`@attr.s()`), we strongly recommend using `@attr.s(kw_only=True, frozen=True)`.\r\n\r\n\r\n\r\n## Contributing\r\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\r\n\r\nPlease make sure to update tests as appropriate.\r\n\r\n## License\r\n[MIT](https://choosealicense.com/licenses/mit/)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeniz195%2Funitdoc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeniz195%2Funitdoc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeniz195%2Funitdoc/lists"}