{"id":19866403,"url":"https://github.com/jumpcrypto/podite","last_synced_at":"2025-05-02T06:30:34.244Z","repository":{"id":42412673,"uuid":"476479623","full_name":"JumpCrypto/podite","owner":"JumpCrypto","description":"Transparent serialization of python plain-old-data classes","archived":false,"fork":false,"pushed_at":"2022-08-31T17:06:47.000Z","size":173,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-04-23T17:06:34.422Z","etag":null,"topics":["blockchain","marshalling","python","rust","serialization","smart-contracts","solana","tool"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/podite/","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/JumpCrypto.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":"2022-03-31T21:10:51.000Z","updated_at":"2022-08-31T17:04:33.000Z","dependencies_parsed_at":"2022-09-12T21:00:54.854Z","dependency_job_id":null,"html_url":"https://github.com/JumpCrypto/podite","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JumpCrypto%2Fpodite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JumpCrypto%2Fpodite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JumpCrypto%2Fpodite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JumpCrypto%2Fpodite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JumpCrypto","download_url":"https://codeload.github.com/JumpCrypto/podite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224298968,"owners_count":17288457,"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":["blockchain","marshalling","python","rust","serialization","smart-contracts","solana","tool"],"created_at":"2024-11-12T15:25:42.699Z","updated_at":"2024-11-12T15:25:42.807Z","avatar_url":"https://github.com/JumpCrypto.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e Podite \u003c/h1\u003e\n\n### Serializing and Deserializing \"Plain Old Data\"\n\nPodite makes interacting with on-chain programs easy - if a Podite dataclass looks exactly like its on-chain rust\nequivalent, then you know it serializes the same way too. No more arcane serialization libraries, no more surprises -\nget exactly what you expect.\n\nPodite was developed alongside [Solmate](https://github.com/nimily/solmate), a client code generator for Solana\nsmart-contracts using the [Anchor Framework](https://github.com/project-serum/anchor) in rust.\n\n### Key Principles\n\n***Simple*** - python types visually mirror on-chain rust types\n\n***Pythonic*** - follows conventions from native `dataclass`\n\n***Smart Defaults*** - automatically detects Borsh and ZeroCopy (bytemuck) account formats during deserialization, but\nallows manually specifying format\n\n***Extensible*** - provide custom serialization to support non-standard account layouts or optimize in\nperformance-critical components\n\n### Quick Start\n\nDefining a message is as simple as:\n\n```python\nfrom podite import pod, U8, Str\n\n\n@pod\nclass Message:\n    message: Str[1000]  # max_length of string\n    likes: U8\n\n\noriginal = Message(\"Serialization doesn't have to be painful\", 19020)\nMessage.to_bytes(original)\n```\n\nThis has a byte representation of:\n\n```\n| length of string | utf-8 string contents | likes  | \n-----------------------------------------------------\n| 4 bytes          | str-len bytes         | 1 byte |\n```\n\nHere is a corresponding rust struct that can deserialize this message:\n\n```rust\nuse borsh::BorshDeserialize;\n\n#[derive(BorshDeserialize)]\nstruct Message {\n    message: String,\n    likes: u8,\n}\n```\n\nPod was originally developed to interact with rust smart-contracts on solana where compact, quick and consistent ser(\nde) (serialization and deserialization) are crucial. Pod by default serializes to borsh format used by most solana\nprograms, but also supports zero-copy ser(de) to C format structs.\n\n```python\nfrom podite import FORMAT_ZERO_COPY\n\n# ... previous \n\n_bytes = Message.to_bytes(original, format=FORMAT_ZERO_COPY)\nround_tripped = Message.from_bytes(_bytes)\n```\n\n```rust\nuse bytemuck::{Pod, ZeroCopy};\n\n#[derive(Pod, ZeroCopy, Clone, Copy, Debug)]\nstruct Message {\n    message: String,\n    likes: u8,\n}\n```\n\nNotice that to deserialize, the format did not need to be specified. As there are currently only 2  \nbinary formats supported by pod, we can compare the number of bytes we are given to the fixed size of a zero-copy\nserialized object. If they are the same, we can deserialize using zero-copy and if they are different, we can attempt to\ndeserialize using the borsh format.\n\nIf you do not want to rely on this implicit format recognition, you can explicitly write the format like this:\n\n```python\nMessage.from_bytes(_bytes, format=...)\n```\n\n### What's with the name?\n\nDuring development, the rust side used the `Pod` (short for plain-old-data) trait from bytemuck to read/write the\nin-memory format, so for the python side we originally used the same name. Podite means **the leg of a crustacean**\nwhich we liked as an homage to rustaceans (aka rust users) and, like the library itself, adds some spice to an otherwise\nbland topic.\n\n### Installation\n\nRequires `python \u003e= 3.9`\n\n```sh\npoetry install podite\n```\n\nor\n\n```sh\npip install podite\n```\n\n### Development Setup\n\nIf you want to contribute to Solmate, follow these steps to get set up:\n\n1. Install [poetry](https://python-poetry.org/docs/#installation)\n2. Install dev dependencies:\n\n```sh\npoetry install\n```\n\n3. Code your change and add tests\n4. Verify tests\n\n```sh\npoetry run pytest\n```\n\n5. Open Pr!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjumpcrypto%2Fpodite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjumpcrypto%2Fpodite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjumpcrypto%2Fpodite/lists"}