{"id":13500358,"url":"https://github.com/capnproto/pycapnp","last_synced_at":"2026-01-27T00:37:11.827Z","repository":{"id":8994523,"uuid":"10744270","full_name":"capnproto/pycapnp","owner":"capnproto","description":"Cap'n Proto serialization/RPC system - Python bindings","archived":false,"fork":false,"pushed_at":"2024-09-25T14:29:28.000Z","size":2407,"stargazers_count":478,"open_issues_count":106,"forks_count":123,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-02-07T17:39:23.455Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Cython","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/capnproto.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-06-17T18:43:24.000Z","updated_at":"2025-02-05T18:08:06.000Z","dependencies_parsed_at":"2023-10-12T00:39:33.657Z","dependency_job_id":"ad61d8f6-b5f9-4a22-afe6-43407892dfa5","html_url":"https://github.com/capnproto/pycapnp","commit_stats":{"total_commits":700,"total_committers":48,"mean_commits":"14.583333333333334","dds":"0.29428571428571426","last_synced_commit":"ed894304a34ce28254779ea5215afe942a0d5b31"},"previous_names":["jparyani/pycapnp"],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capnproto%2Fpycapnp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capnproto%2Fpycapnp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capnproto%2Fpycapnp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capnproto%2Fpycapnp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/capnproto","download_url":"https://codeload.github.com/capnproto/pycapnp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240177055,"owners_count":19760308,"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":[],"created_at":"2024-07-31T22:00:57.200Z","updated_at":"2026-01-27T00:37:11.798Z","avatar_url":"https://github.com/capnproto.png","language":"Cython","funding_links":[],"categories":["Cython"],"sub_categories":[],"readme":"# pycapnp\n\n[![Packaging Status](https://github.com/capnproto/pycapnp/workflows/Packaging%20Test/badge.svg)](https://github.com/capnproto/pycapnp/actions)\n[![manylinux2014 Status](https://github.com/capnproto/pycapnp/workflows/manylinux2014/badge.svg)](https://github.com/capnproto/pycapnp/actions)\n[![PyPI version](https://badge.fury.io/py/pycapnp.svg)](https://badge.fury.io/py/pycapnp)\n\n[Cap'n'proto Mailing List](https://github.com/capnproto/capnproto/discussions) [Documentation](https://capnproto.github.io/pycapnp)\n\n\n## Requirements\n\n* C++14 supported compiler\n  - gcc 6.1+ (5+ may work)\n  - clang 6 (3.4+ may work)\n  - Visual Studio 2017+\n* cmake (needed for bundled capnproto)\n  - ninja (macOS + Linux)\n  - Visual Studio 2017+\n* capnproto-1.0 (\u003e=0.8.0 will also work if linking to system libraries)\n  - Not necessary if using bundled capnproto\n* Python development headers (i.e. Python.h)\n  - Distributables from python.org include these, however they are usually in a separate package on Linux distributions\n\n32-bit Linux requires that capnproto be compiled with `-fPIC`. This is usually set correctly unless you are compiling canproto yourself. This is also called `-DCMAKE_POSITION_INDEPENDENT_CODE=1` for cmake.\n\npycapnp has additional development dependencies, including cython and pytest. See requirements.txt for them all.\n\n\n## Building and installation\n\nInstall with `pip install pycapnp`. You can set the CC environment variable to control which compiler is used, ie `CC=gcc-8.2 pip install pycapnp`.\n\nOr you can clone the repo like so:\n\n```bash\ngit clone https://github.com/capnproto/pycapnp.git\ncd pycapnp\npip install .\n```\n\nBy default, the setup script will automatically use the locally installed Cap'n Proto.\nIf Cap'n Proto is not installed, it will bundle and build the matching Cap'n Proto library.\n\nTo enforce bundling, the Cap'n Proto library:\n\n```bash\npip install . -C force-bundled-libcapnp=True\n```\n\nIf you wish to install using the latest upstream C++ Cap'n Proto:\n\n```bash\npip install . \\\n    -C force-bundled-libcapnp=True \\\n    -C libcapnp-url=\"https://github.com/capnproto/capnproto/archive/master.tar.gz\"\n```\n\nTo enforce using the installed Cap'n Proto from the system:\n\n```bash\npip install . -C force-system-libcapnp=True\n```\n\nThe bundling system isn't that smart so it might be necessary to clean up the bundled build when changing versions:\n\n```bash\npython setup.py clean\n```\n\n\n## Stub-file generation\n\nWhile not directly supported by pycapnp, a tool has been created to help generate pycapnp stubfile to assist with development (this is very helpful if you're new to pypcapnp!). See [#289](https://github.com/capnproto/pycapnp/pull/289#event-9078216721) for more details.\n\n[Python Capnp Stub Generator](https://gitlab.com/mic_public/tools/python-helpers/capnp-stub-generator)\n\n\n## Python Versions\n\nPython 3.8+ is supported.\n\n\n## Development\n\nGit flow has been abandoned, use master.\n\nTo test, use a pipenv (or install requirements.txt and run pytest manually).\n```bash\npip install pipenv\npipenv install\npipenv run pytest\n```\n\n\n### Binary Packages\n\nBuilding a Python wheel distributiion\n\n```bash\npip wheel .\n```\n\n## Documentation/Example\n\nThere is some basic documentation [here](http://capnproto.github.io/pycapnp/).\n\nMake sure to look at the [examples](examples). The examples are generally kept up to date with the recommended usage of the library.\n\nThe examples directory has one example that shows off pycapnp quite nicely. Here it is, reproduced:\n\n```python\nimport os\nimport capnp\n\nimport addressbook_capnp\n\ndef writeAddressBook(file):\n    addresses = addressbook_capnp.AddressBook.new_message()\n    people = addresses.init('people', 2)\n\n    alice = people[0]\n    alice.id = 123\n    alice.name = 'Alice'\n    alice.email = 'alice@example.com'\n    alicePhones = alice.init('phones', 1)\n    alicePhones[0].number = \"555-1212\"\n    alicePhones[0].type = 'mobile'\n    alice.employment.school = \"MIT\"\n\n    bob = people[1]\n    bob.id = 456\n    bob.name = 'Bob'\n    bob.email = 'bob@example.com'\n    bobPhones = bob.init('phones', 2)\n    bobPhones[0].number = \"555-4567\"\n    bobPhones[0].type = 'home'\n    bobPhones[1].number = \"555-7654\"\n    bobPhones[1].type = 'work'\n    bob.employment.unemployed = None\n\n    addresses.write(file)\n\n\ndef printAddressBook(file):\n    addresses = addressbook_capnp.AddressBook.read(file)\n\n    for person in addresses.people:\n        print(person.name, ':', person.email)\n        for phone in person.phones:\n            print(phone.type, ':', phone.number)\n\n        which = person.employment.which()\n        print(which)\n\n        if which == 'unemployed':\n            print('unemployed')\n        elif which == 'employer':\n            print('employer:', person.employment.employer)\n        elif which == 'school':\n            print('student at:', person.employment.school)\n        elif which == 'selfEmployed':\n            print('self employed')\n        print()\n\n\nif __name__ == '__main__':\n    f = open('example', 'w')\n    writeAddressBook(f)\n\n    f = open('example', 'r')\n    printAddressBook(f)\n```\n\nAlso, pycapnp has gained RPC features that include pipelining and a promise style API. Refer to the calculator example in the examples directory for a much better demonstration:\n\n```python\nimport asyncio\nimport capnp\nimport socket\n\nimport test_capability_capnp\n\n\nclass Server(test_capability_capnp.TestInterface.Server):\n\n    def __init__(self, val=1):\n        self.val = val\n\n    async def foo(self, i, j, **kwargs):\n        return str(i * 5 + self.val)\n\n\nasync def client(read_end):\n    client = capnp.TwoPartyClient(read_end)\n\n    cap = client.bootstrap()\n    cap = cap.cast_as(test_capability_capnp.TestInterface)\n\n    remote = cap.foo(i=5)\n    response = await remote\n\n    assert response.x == '125'\n\nasync def main():\n    client_end, server_end = socket.socketpair(socket.AF_UNIX)\n    # This is a toy example using socketpair.\n    # In real situations, you can use any socket.\n\n    client_end = await capnp.AsyncIoStream.create_connection(sock=client_end)\n    server_end = await capnp.AsyncIoStream.create_connection(sock=server_end)\n\n    _ = capnp.TwoPartyServer(server_end, bootstrap=Server(100))\n    await client(client_end)\n\n\nif __name__ == '__main__':\n    asyncio.run(capnp.run(main()))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapnproto%2Fpycapnp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcapnproto%2Fpycapnp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapnproto%2Fpycapnp/lists"}