{"id":26807,"library":"borsh-construct","title":"borsh-construct","description":"Python implementation of Borsh serialization, built on the Construct library. Version 0.1.0. Low release cadence.","status":"active","version":"0.1.0","language":"python","source_language":"en","source_url":"https://github.com/near/borsh-construct-py","tags":["borsh","serialization","near","construct"],"install":[{"cmd":"pip install borsh-construct","lang":"bash","label":"Standard install"}],"dependencies":[{"reason":"Core dependency; borsh-construct is built on top of construct.","package":"construct","optional":false}],"imports":[{"note":"'borsh' is a separate package; borsh-construct uses borsh_construct.","wrong":"from borsh import BorshStruct","symbol":"BorshStruct","correct":"from borsh_construct import BorshStruct"},{"note":"These types are also in construct, but borsh_construct provides Borsh-specific versions.","symbol":"U8, U16, U32, U64, U128, I8, I16, I32, I64, I128, F32, F64, String, Vec, Option, Enum, Struct","correct":"from borsh_construct import U8, U16, ..."}],"quickstart":{"code":"from borsh_construct import BorshStruct, U8, U32, String, Vec\n\n# Define a simple Borsh schema\nclass Person(BorshStruct):\n    name = String\n    age = U32\n    hobbies = Vec(String)\n\n# Encode an instance\ndata = Person.encode({'name': 'Alice', 'age': 30, 'hobbies': ['reading', 'coding']})\nprint('Encoded:', data.hex())\n\n# Decode back\ndecoded = Person.decode(data)\nprint('Decoded:', decoded)","lang":"python","description":"Define a Borsh-serializable struct, encode, and decode."},"warnings":[{"fix":"Always use types imported from borsh_construct rather than construct directly when working with Borsh serialization.","message":"borsh-construct uses the Construct library under the hood. If you mix borsh_construct types with pure construct types, serialization may fail silently or produce non-Borsh-compatible output.","severity":"gotcha","affected_versions":"all"},{"fix":"Define fields in the same order as the schema you are conforming to. Do not assume alphabetical or insertion order.","message":"Borsh is strict about field order. When subclassing BorshStruct, field order in class definition matters and must match the schema exactly.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use 'from borsh_construct import ...' instead.","cause":"Installed borsh-construct but tried to import 'borsh' (the JavaScript-like package).","error":"ModuleNotFoundError: No module named 'borsh'"},{"fix":"Ensure you have the latest version: pip install --upgrade borsh-construct. Check spelling: it is 'BorshStruct'.","cause":"Outdated version or misspelling (e.g., 'BorshStruct' vs 'BorshStruct<wrong>').","error":"AttributeError: module 'borsh_construct' has no attribute 'BorshStruct'"},{"fix":"Ensure that arrays are passed as lists, not dicts. For Vec fields, provide a list.","cause":"Passed a dict to a field that expects a list (e.g., Vec).","error":"construct.core.ConstructError: Error in field '...' : expected Sequence, got dict"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}