{"id":37078863,"url":"https://github.com/moff4/packer","last_synced_at":"2026-01-14T09:32:56.589Z","repository":{"id":62405093,"uuid":"550090422","full_name":"moff4/packer","owner":"moff4","description":"fast and light packer python dataclasses to binary data","archived":false,"fork":false,"pushed_at":"2022-11-15T14:19:15.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-03T12:41:51.828Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moff4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-12T07:32:11.000Z","updated_at":"2022-11-01T09:18:09.000Z","dependencies_parsed_at":"2023-01-22T06:02:45.439Z","dependency_job_id":null,"html_url":"https://github.com/moff4/packer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/moff4/packer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moff4%2Fpacker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moff4%2Fpacker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moff4%2Fpacker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moff4%2Fpacker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moff4","download_url":"https://codeload.github.com/moff4/packer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moff4%2Fpacker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28416096,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T08:38:59.149Z","status":"ssl_error","status_checked_at":"2026-01-14T08:38:43.588Z","response_time":107,"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":"2026-01-14T09:32:56.002Z","updated_at":"2026-01-14T09:32:56.581Z","avatar_url":"https://github.com/moff4.png","language":"Python","funding_links":["https://www.buymeacoffee.com/komissarov"],"categories":[],"sub_categories":[],"readme":"\n# BINARY PACKER #\n\nLight and fast packer python dataclasses to bytes\n\n[![Build Status](https://app.travis-ci.com/moff4/packer.svg?token=NypENqxc3msyxJUab3w4\u0026branch=master)](https://app.travis-ci.com/moff4/packer)\n[![CodeFactor](https://www.codefactor.io/repository/github/moff4/packer/badge?s=e9364aaef867be60363f528cdb9c58eaf7c1c64b)](https://www.codefactor.io/repository/github/moff4/packer)\n\n\n## Install\n\nUsing PIP:\n\n```bash\npip install binary-packer\n```\n\n## How it works\n\nIt's a wrap! A wrap over stdlib [struct](https://docs.python.org/3/library/struct.html)  \nSo it converts values into bytes using `struct.pack()`.  \nBut it does not save keys and values' types in bytes, so be sure about how you configure packer for packing and unpacking. \n\n## Why and when should it be used?\n\nWe all like to use json/xml/pickle and other popular libraries for dumping data, but sometimes they are too slow or result's size ot too large.  \nThis library works much faster than other packers like json and makes result a lot more compact.\n\n## Example of Usage\n\n```python\nimport uuid\nfrom typing import Optional\nfrom dataclasses import dataclass\n\nfrom binary_packer import PackerFactory, FieldStruct\n\n\n@dataclass\nclass Person:\n    id: uuid.UUID\n    name: Optional[str] = None  # max length is 20 bytes\n    age: Optional[int] = None\n\nperson = Person(id=uuid.uuid4(), name='vaschevsky', age=33)\n\n\nfactory = PackerFactory(\n    Person,\n    id=FieldStruct[uuid.UUID, bytes](\n        '16s',  # '16s' is for bytearray length of 16, uuid as bytearray also 16 bytes\n        encoder=lambda uid: uid.bytes,\n        decoder=lambda uid_as_bytes: uuid.UUID(bytes=uid_as_bytes),\n    ),\n    name=FieldStruct[str, bytes](\n        '20s',  # '20s' is for bytearray length of 20, each byte is ascii char\n        encoder=lambda name: name.encode(),\n        decoder=lambda name_as_bytes: name_as_bytes.decode().strip('\\x00'),\n    ),\n    age=FieldStruct[int, int](\n        'B',  #  'B' is for unsigned tiny int (1 byte) =\u003e age can be any value from 0 to 255,\n        # no need for custom encoder/decoder\n    )\n)\n\npacker_1 = factory.make_packer('id', 'name', 'age')\npacker_2 = factory.make_packer('id', 'name')\npacker_3 = factory.make_packer('id')\n\nfor packer in (packer_1, packer_2, packer_3):\n    data_as_bytes = packer.pack(person)\n    print(f'{len(data_as_bytes)=}')\n    unpacked_person = packer.unpack(data_as_bytes)\n    print(f'{unpacked_person=}')\n\n# will be printed:\n# len(data_as_bytes)=37\n# unpacked_person=Person(id=UUID('a72decb7-7f9e-497b-ac91-692e316a7580'), name='vaschevsky', age=33)\n# len(data_as_bytes)=36\n# unpacked_person=Person(id=UUID('a72decb7-7f9e-497b-ac91-692e316a7580'), name='vaschevsky', age=None)\n# len(data_as_bytes)=16\n# unpacked_person=Person(id=UUID('a72decb7-7f9e-497b-ac91-692e316a7580'), name=None, age=None)\n```\n\n\n[![Buy Me A Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/komissarov)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoff4%2Fpacker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoff4%2Fpacker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoff4%2Fpacker/lists"}