glowcap 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. glowcap-0.1.1/LICENSE-APACHE +201 -0
  2. glowcap-0.1.1/PKG-INFO +171 -0
  3. glowcap-0.1.1/README.md +154 -0
  4. glowcap-0.1.1/glowcap/__init__.py +189 -0
  5. glowcap-0.1.1/glowcap/_abi_value.py +308 -0
  6. glowcap-0.1.1/glowcap/_action.py +145 -0
  7. glowcap-0.1.1/glowcap/_archive_contract.py +25 -0
  8. glowcap-0.1.1/glowcap/_carrier_failure.py +69 -0
  9. glowcap-0.1.1/glowcap/_constants.py +80 -0
  10. glowcap-0.1.1/glowcap/_constants_gen.py +220 -0
  11. glowcap-0.1.1/glowcap/_context.py +239 -0
  12. glowcap-0.1.1/glowcap/_dial.py +399 -0
  13. glowcap-0.1.1/glowcap/_driver/__init__.py +1 -0
  14. glowcap-0.1.1/glowcap/_driver/finalizer.py +109 -0
  15. glowcap-0.1.1/glowcap/_driver/release.py +73 -0
  16. glowcap-0.1.1/glowcap/_driver/transport.py +39 -0
  17. glowcap-0.1.1/glowcap/_driver_event.py +52 -0
  18. glowcap-0.1.1/glowcap/_driver_failure.py +143 -0
  19. glowcap-0.1.1/glowcap/_errors.py +189 -0
  20. glowcap-0.1.1/glowcap/_failure.py +219 -0
  21. glowcap-0.1.1/glowcap/_ffi.py +153 -0
  22. glowcap-0.1.1/glowcap/_ffi_driver.py +138 -0
  23. glowcap-0.1.1/glowcap/_ffi_host.py +217 -0
  24. glowcap-0.1.1/glowcap/_ffi_inproc.py +39 -0
  25. glowcap-0.1.1/glowcap/_ffi_iroh.py +90 -0
  26. glowcap-0.1.1/glowcap/_ffi_ocapn.py +278 -0
  27. glowcap-0.1.1/glowcap/_ffi_onion.py +67 -0
  28. glowcap-0.1.1/glowcap/_ffi_relay.py +50 -0
  29. glowcap-0.1.1/glowcap/_ffi_tcp.py +55 -0
  30. glowcap-0.1.1/glowcap/_ffi_webrtc.py +156 -0
  31. glowcap-0.1.1/glowcap/_gc.py +239 -0
  32. glowcap-0.1.1/glowcap/_host/__init__.py +493 -0
  33. glowcap-0.1.1/glowcap/_host/finalizer.py +176 -0
  34. glowcap-0.1.1/glowcap/_host/lifecycle.py +391 -0
  35. glowcap-0.1.1/glowcap/_host/progress.py +294 -0
  36. glowcap-0.1.1/glowcap/_host/publication.py +347 -0
  37. glowcap-0.1.1/glowcap/_host/state.py +114 -0
  38. glowcap-0.1.1/glowcap/_host/vows.py +116 -0
  39. glowcap-0.1.1/glowcap/_host_action_gen.py +133 -0
  40. glowcap-0.1.1/glowcap/_iroh_async.py +486 -0
  41. glowcap-0.1.1/glowcap/_iroh_ffi.py +484 -0
  42. glowcap-0.1.1/glowcap/_layouts_gen.py +325 -0
  43. glowcap-0.1.1/glowcap/_lib_resolve.py +391 -0
  44. glowcap-0.1.1/glowcap/_lifecycle.py +75 -0
  45. glowcap-0.1.1/glowcap/_listener.py +65 -0
  46. glowcap-0.1.1/glowcap/_locator.py +343 -0
  47. glowcap-0.1.1/glowcap/_loop/__init__.py +353 -0
  48. glowcap-0.1.1/glowcap/_loop/configuration.py +40 -0
  49. glowcap-0.1.1/glowcap/_loop/dialing.py +66 -0
  50. glowcap-0.1.1/glowcap/_loop/errors.py +26 -0
  51. glowcap-0.1.1/glowcap/_loop/lifecycle.py +248 -0
  52. glowcap-0.1.1/glowcap/_loop/listeners.py +288 -0
  53. glowcap-0.1.1/glowcap/_loop/progress.py +277 -0
  54. glowcap-0.1.1/glowcap/_loop/sessions.py +151 -0
  55. glowcap-0.1.1/glowcap/_loop/state.py +114 -0
  56. glowcap-0.1.1/glowcap/_pin.py +82 -0
  57. glowcap-0.1.1/glowcap/_promise.py +428 -0
  58. glowcap-0.1.1/glowcap/_pump.py +303 -0
  59. glowcap-0.1.1/glowcap/_server.py +136 -0
  60. glowcap-0.1.1/glowcap/_session/__init__.py +301 -0
  61. glowcap-0.1.1/glowcap/_session/lifecycle.py +410 -0
  62. glowcap-0.1.1/glowcap/_session/profile.py +51 -0
  63. glowcap-0.1.1/glowcap/_session/verbs.py +288 -0
  64. glowcap-0.1.1/glowcap/_session/writer.py +152 -0
  65. glowcap-0.1.1/glowcap/_sigs_gen.py +399 -0
  66. glowcap-0.1.1/glowcap/_socket_address.py +10 -0
  67. glowcap-0.1.1/glowcap/_tcp_listen.py +163 -0
  68. glowcap-0.1.1/glowcap/_trace.py +361 -0
  69. glowcap-0.1.1/glowcap/_trampoline.py +474 -0
  70. glowcap-0.1.1/glowcap/_transport.py +102 -0
  71. glowcap-0.1.1/glowcap/_value.py +156 -0
  72. glowcap-0.1.1/glowcap/_ws.py +104 -0
  73. glowcap-0.1.1/glowcap/c-abi-resolve.json +23 -0
  74. glowcap-0.1.1/glowcap/inproc.py +248 -0
  75. glowcap-0.1.1/glowcap/iroh.py +24 -0
  76. glowcap-0.1.1/glowcap/onion.py +510 -0
  77. glowcap-0.1.1/glowcap/py.typed +0 -0
  78. glowcap-0.1.1/glowcap/relay.py +298 -0
  79. glowcap-0.1.1/glowcap/tcp.py +443 -0
  80. glowcap-0.1.1/glowcap/webrtc.py +540 -0
  81. glowcap-0.1.1/glowcap.egg-info/PKG-INFO +171 -0
  82. glowcap-0.1.1/glowcap.egg-info/SOURCES.txt +85 -0
  83. glowcap-0.1.1/glowcap.egg-info/dependency_links.txt +1 -0
  84. glowcap-0.1.1/glowcap.egg-info/requires.txt +3 -0
  85. glowcap-0.1.1/glowcap.egg-info/top_level.txt +1 -0
  86. glowcap-0.1.1/pyproject.toml +41 -0
  87. glowcap-0.1.1/setup.cfg +4 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Glowcap LLC
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
glowcap-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,171 @@
1
+ Metadata-Version: 2.4
2
+ Name: glowcap
3
+ Version: 0.1.1
4
+ Summary: Python ctypes binding for the glowcap C ABI archives (codec-neutral CapTP core for OCapN).
5
+ Author: Glowcap LLC
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/glowcap-org/glowcap
8
+ Project-URL: Homepage, https://glowcap.org
9
+ Project-URL: Documentation, https://glowcap.org
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Requires-Python: >=3.11
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE-APACHE
14
+ Provides-Extra: rendezvous
15
+ Requires-Dist: websockets; extra == "rendezvous"
16
+ Dynamic: license-file
17
+
18
+ # Python binding
19
+
20
+ This package lets Python connect to OCapN peers, call their objects, and host
21
+ objects of its own. It uses `ctypes`, `asyncio`, and the standard library, and
22
+ needs the CPython version `pyproject.toml` declares on an LP64 (64-bit Unix)
23
+ platform. Terms such as locator, vat, and sturdyref are defined in the
24
+ [glossary](../../docs/capabilities.md#glossary).
25
+
26
+ ```sh
27
+ pip install glowcap
28
+ ```
29
+
30
+ On first import the package downloads the C libraries of its version from the
31
+ GitHub release and verifies them against its checksum file. Set
32
+ `GLOWCAP_LIB_DIR` to an extracted C SDK's `lib/` directory to use a local copy.
33
+ In a checkout of the repository, run `zig build` and make the tree's package
34
+ importable instead:
35
+
36
+ ```sh
37
+ export PYTHONPATH="$PWD/bindings/python${PYTHONPATH:+:$PYTHONPATH}"
38
+ ```
39
+
40
+ ```python
41
+ import asyncio
42
+
43
+ from glowcap import Runtime, tcp, VowBroken
44
+
45
+
46
+ async def main():
47
+ peer_key = "<64 lowercase hex characters from the server>"
48
+ async with Runtime.open(provider=tcp.provider()) as runtime:
49
+ async with await runtime.connect(tcp.noise.locator(peer_key, "127.0.0.1", 9099)) as session:
50
+ greeter = await session.fetch("greeter")
51
+ try:
52
+ print(await session.send(greeter, "greet", ["world"]))
53
+ except VowBroken as reason:
54
+ print(f"the greeter refused: {reason}")
55
+
56
+
57
+ asyncio.run(main())
58
+ ```
59
+
60
+ - `fetch` and `send` start the inbound loop when first used, so a client that
61
+ only makes calls does not need `session.serve()`.
62
+ - `await session.closed()` waits for the session to end without closing it or
63
+ starting that loop. Cancelling the waiter leaves the session running.
64
+ - `Host.publish_durable(behavior, entropy=None)` publishes `behavior` under a
65
+ durable swiss number, the secret name a peer uses to fetch it later. Pass the
66
+ same entropy to a Host reconstructed from the same seed to restore that name.
67
+
68
+ ## Sessions and actors
69
+
70
+ Python values map directly to glowcap values: integers, floats, booleans,
71
+ bytes, strings, and lists, plus `Symbol`, `Keyword`, `Set`, `Tagged`, `Struct`,
72
+ the fulfilled-data `ErrorValue`, and the capability type `Ref`. Returning an
73
+ `ErrorValue` fulfills the caller's `RemotePromise` with that error as data.
74
+ Raising an exception or returning a broken vow rejects it.
75
+
76
+ `await tcp.listen(host, port)` returns a `tcp.Server` whose iterator yields a
77
+ `Session` for each partner. `publish` and `spawn` host ordinary Python
78
+ callables. `send` returns a `RemotePromise`, implemented as an
79
+ `asyncio.Future`, and that promise can be the target of another send.
80
+
81
+ Under `Runtime` and `listen`, an `iroh`, `noise-tcp`, `keyed-tcp`, or `tcp`
82
+ connection runs on glowcap's driver loop, one event loop in the C library that
83
+ owns the sockets, frames and moves bytes, and releases finished sessions.
84
+ Python loads the separate Host and driver libraries and steps the loop, while
85
+ asyncio waits on a file descriptor that signals when the loop has work.
86
+
87
+ Pass `iroh.provider(config)`, `tcp.provider(config)`, or another transport
88
+ package to choose a transport. The driver starts with no transports and
89
+ installs the one you pass. A routed `keyed-relay` or `noise-relay` locator
90
+ likewise loads the relay library and installs its provider.
91
+
92
+ `Runtime.open(adopt_host=host, ...)` transfers an existing Host into the
93
+ Runtime. `await runtime.close()` then shuts that Host down for good.
94
+
95
+ `tcp.listen`, `tcp.keyed.listen`, and `tcp.noise.listen` return the same
96
+ `tcp.Server`. Its `locator` and `uri` are ready to hand to `Runtime.connect`.
97
+
98
+ - Pass a 32-byte `seed` to keep the same identity (the designator in the
99
+ locator) across restarts.
100
+ - The driver loop accepts incoming connections and limits concurrent
101
+ handshakes.
102
+ - A wildcard `bind_host` requires `advertised_host`, the name or address
103
+ partners dial. glowcap puts it in the locator because it cannot infer
104
+ reachability from the bind.
105
+
106
+ `relay.keyed.listen` and `relay.noise.listen` return the same `DriverServer`
107
+ shape over a registered relay route. Their `locator` and `uri` carry the
108
+ durable key and the rendezvous relay that partners dial.
109
+
110
+ A handoff is how one peer gives you a reference to an object hosted by a third
111
+ peer. With one Host shared across sessions, a handoff needs no extra code. The
112
+ less common `send_redeeming` call returns both the answer and `via`, the
113
+ session to the peer that hosts the object. Host a reply capability on `via`. A
114
+ local reference is valid only in the session where it was exported.
115
+
116
+ ## Transports
117
+
118
+ | Module | Purpose |
119
+ | --- | --- |
120
+ | `glowcap` | Async sessions, hosts, values, locators, and actors. |
121
+ | `glowcap.tcp` | Typed TCP-profile locators, the complete provider package, and blocking frame handles. |
122
+ | `glowcap.inproc` | Blocking in-process connections. |
123
+ | `glowcap.onion` | Configured `listen` through a Tor daemon you run, plus raw Netlayer handles for a program that owns its own loop. |
124
+ | `glowcap.iroh` | Optional encrypted QUIC and `listen`. |
125
+ | `glowcap.webrtc` | Optional WebRTC dial and listen. See below. |
126
+ | `glowcap.relay` | `keyed-relay`/`noise-relay` provider composition and managed listeners. |
127
+
128
+ WebRTC needs a `SignalingAuthority` that you write to carry each exchange's
129
+ offer, answer, and candidates. `webrtc.provider(signaling)` installs the dial.
130
+ `await webrtc.listen(signaling)` returns a `Server` you iterate for sessions.
131
+ Hand each inbound offer to `server.provide_offer(designator, sdp)`.
132
+
133
+ The application imports only the transport modules it composes. A TCP-only
134
+ program never loads the iroh or WebRTC library.
135
+
136
+ A `keyed-relay` locator names a peer that opens no socket of its own. Instead,
137
+ a relay holds inbound connections for it under its key.
138
+
139
+ - When the locator carries a `rendezvous-relay` hint, `Runtime.connect` routes
140
+ through the relay provider.
141
+ - For a bare locator, use `relay.connector(config)`. The route comes from the
142
+ locator's hint or from the connector's configuration, as in every binding.
143
+ Connections go through the connector only when your code creates one.
144
+ - The connector's client is the one optional dependency: install
145
+ `glowcap[rendezvous]`. Repository checks install that extra
146
+ from the committed lock with
147
+ `uv run --project bindings/python --extra rendezvous --locked`.
148
+
149
+ The lower-level transports are also available directly:
150
+
151
+ ```python
152
+ from glowcap.tcp import TcpNetlayer
153
+
154
+ with TcpNetlayer() as netlayer:
155
+ listener = netlayer.listen("127.0.0.1", 0)
156
+ connection = netlayer.connect("127.0.0.1", listener.port())
157
+ ```
158
+
159
+ ## Tests
160
+
161
+ ```sh
162
+ zig build python-dogfood # the package against a glowcap peer
163
+ zig build python-goblins-interop # the package against a Spritely Goblins peer
164
+ ```
165
+
166
+ `zig build bindings` builds the libraries and runs the tests for every
167
+ language binding. [`zig_smoke.py`](zig_smoke.py) is a complete example program.
168
+
169
+ For the shared API, read the [binding overview](../README.md). Maintainers of
170
+ the private FFI loaders and pump should read
171
+ [Developing a binding](../DEVELOPING.md).
@@ -0,0 +1,154 @@
1
+ # Python binding
2
+
3
+ This package lets Python connect to OCapN peers, call their objects, and host
4
+ objects of its own. It uses `ctypes`, `asyncio`, and the standard library, and
5
+ needs the CPython version `pyproject.toml` declares on an LP64 (64-bit Unix)
6
+ platform. Terms such as locator, vat, and sturdyref are defined in the
7
+ [glossary](../../docs/capabilities.md#glossary).
8
+
9
+ ```sh
10
+ pip install glowcap
11
+ ```
12
+
13
+ On first import the package downloads the C libraries of its version from the
14
+ GitHub release and verifies them against its checksum file. Set
15
+ `GLOWCAP_LIB_DIR` to an extracted C SDK's `lib/` directory to use a local copy.
16
+ In a checkout of the repository, run `zig build` and make the tree's package
17
+ importable instead:
18
+
19
+ ```sh
20
+ export PYTHONPATH="$PWD/bindings/python${PYTHONPATH:+:$PYTHONPATH}"
21
+ ```
22
+
23
+ ```python
24
+ import asyncio
25
+
26
+ from glowcap import Runtime, tcp, VowBroken
27
+
28
+
29
+ async def main():
30
+ peer_key = "<64 lowercase hex characters from the server>"
31
+ async with Runtime.open(provider=tcp.provider()) as runtime:
32
+ async with await runtime.connect(tcp.noise.locator(peer_key, "127.0.0.1", 9099)) as session:
33
+ greeter = await session.fetch("greeter")
34
+ try:
35
+ print(await session.send(greeter, "greet", ["world"]))
36
+ except VowBroken as reason:
37
+ print(f"the greeter refused: {reason}")
38
+
39
+
40
+ asyncio.run(main())
41
+ ```
42
+
43
+ - `fetch` and `send` start the inbound loop when first used, so a client that
44
+ only makes calls does not need `session.serve()`.
45
+ - `await session.closed()` waits for the session to end without closing it or
46
+ starting that loop. Cancelling the waiter leaves the session running.
47
+ - `Host.publish_durable(behavior, entropy=None)` publishes `behavior` under a
48
+ durable swiss number, the secret name a peer uses to fetch it later. Pass the
49
+ same entropy to a Host reconstructed from the same seed to restore that name.
50
+
51
+ ## Sessions and actors
52
+
53
+ Python values map directly to glowcap values: integers, floats, booleans,
54
+ bytes, strings, and lists, plus `Symbol`, `Keyword`, `Set`, `Tagged`, `Struct`,
55
+ the fulfilled-data `ErrorValue`, and the capability type `Ref`. Returning an
56
+ `ErrorValue` fulfills the caller's `RemotePromise` with that error as data.
57
+ Raising an exception or returning a broken vow rejects it.
58
+
59
+ `await tcp.listen(host, port)` returns a `tcp.Server` whose iterator yields a
60
+ `Session` for each partner. `publish` and `spawn` host ordinary Python
61
+ callables. `send` returns a `RemotePromise`, implemented as an
62
+ `asyncio.Future`, and that promise can be the target of another send.
63
+
64
+ Under `Runtime` and `listen`, an `iroh`, `noise-tcp`, `keyed-tcp`, or `tcp`
65
+ connection runs on glowcap's driver loop, one event loop in the C library that
66
+ owns the sockets, frames and moves bytes, and releases finished sessions.
67
+ Python loads the separate Host and driver libraries and steps the loop, while
68
+ asyncio waits on a file descriptor that signals when the loop has work.
69
+
70
+ Pass `iroh.provider(config)`, `tcp.provider(config)`, or another transport
71
+ package to choose a transport. The driver starts with no transports and
72
+ installs the one you pass. A routed `keyed-relay` or `noise-relay` locator
73
+ likewise loads the relay library and installs its provider.
74
+
75
+ `Runtime.open(adopt_host=host, ...)` transfers an existing Host into the
76
+ Runtime. `await runtime.close()` then shuts that Host down for good.
77
+
78
+ `tcp.listen`, `tcp.keyed.listen`, and `tcp.noise.listen` return the same
79
+ `tcp.Server`. Its `locator` and `uri` are ready to hand to `Runtime.connect`.
80
+
81
+ - Pass a 32-byte `seed` to keep the same identity (the designator in the
82
+ locator) across restarts.
83
+ - The driver loop accepts incoming connections and limits concurrent
84
+ handshakes.
85
+ - A wildcard `bind_host` requires `advertised_host`, the name or address
86
+ partners dial. glowcap puts it in the locator because it cannot infer
87
+ reachability from the bind.
88
+
89
+ `relay.keyed.listen` and `relay.noise.listen` return the same `DriverServer`
90
+ shape over a registered relay route. Their `locator` and `uri` carry the
91
+ durable key and the rendezvous relay that partners dial.
92
+
93
+ A handoff is how one peer gives you a reference to an object hosted by a third
94
+ peer. With one Host shared across sessions, a handoff needs no extra code. The
95
+ less common `send_redeeming` call returns both the answer and `via`, the
96
+ session to the peer that hosts the object. Host a reply capability on `via`. A
97
+ local reference is valid only in the session where it was exported.
98
+
99
+ ## Transports
100
+
101
+ | Module | Purpose |
102
+ | --- | --- |
103
+ | `glowcap` | Async sessions, hosts, values, locators, and actors. |
104
+ | `glowcap.tcp` | Typed TCP-profile locators, the complete provider package, and blocking frame handles. |
105
+ | `glowcap.inproc` | Blocking in-process connections. |
106
+ | `glowcap.onion` | Configured `listen` through a Tor daemon you run, plus raw Netlayer handles for a program that owns its own loop. |
107
+ | `glowcap.iroh` | Optional encrypted QUIC and `listen`. |
108
+ | `glowcap.webrtc` | Optional WebRTC dial and listen. See below. |
109
+ | `glowcap.relay` | `keyed-relay`/`noise-relay` provider composition and managed listeners. |
110
+
111
+ WebRTC needs a `SignalingAuthority` that you write to carry each exchange's
112
+ offer, answer, and candidates. `webrtc.provider(signaling)` installs the dial.
113
+ `await webrtc.listen(signaling)` returns a `Server` you iterate for sessions.
114
+ Hand each inbound offer to `server.provide_offer(designator, sdp)`.
115
+
116
+ The application imports only the transport modules it composes. A TCP-only
117
+ program never loads the iroh or WebRTC library.
118
+
119
+ A `keyed-relay` locator names a peer that opens no socket of its own. Instead,
120
+ a relay holds inbound connections for it under its key.
121
+
122
+ - When the locator carries a `rendezvous-relay` hint, `Runtime.connect` routes
123
+ through the relay provider.
124
+ - For a bare locator, use `relay.connector(config)`. The route comes from the
125
+ locator's hint or from the connector's configuration, as in every binding.
126
+ Connections go through the connector only when your code creates one.
127
+ - The connector's client is the one optional dependency: install
128
+ `glowcap[rendezvous]`. Repository checks install that extra
129
+ from the committed lock with
130
+ `uv run --project bindings/python --extra rendezvous --locked`.
131
+
132
+ The lower-level transports are also available directly:
133
+
134
+ ```python
135
+ from glowcap.tcp import TcpNetlayer
136
+
137
+ with TcpNetlayer() as netlayer:
138
+ listener = netlayer.listen("127.0.0.1", 0)
139
+ connection = netlayer.connect("127.0.0.1", listener.port())
140
+ ```
141
+
142
+ ## Tests
143
+
144
+ ```sh
145
+ zig build python-dogfood # the package against a glowcap peer
146
+ zig build python-goblins-interop # the package against a Spritely Goblins peer
147
+ ```
148
+
149
+ `zig build bindings` builds the libraries and runs the tests for every
150
+ language binding. [`zig_smoke.py`](zig_smoke.py) is a complete example program.
151
+
152
+ For the shared API, read the [binding overview](../README.md). Maintainers of
153
+ the private FFI loaders and pump should read
154
+ [Developing a binding](../DEVELOPING.md).