@@ -0,0 +1,131 @@
3+Airlock is the term to describe the set of APIs for interacting with a running Urbit ship from outside of the Urbit network.
7+Urlock-py is a python library for using Airlock.
9+It consists of a single class `Urlock`. Methods are below.
15+ `url` - url to the http interface of the running ship
17+ `code` - the `+code` of the ship, should never be published
22+ Connect to the running ship
25+`poke(ship, app, mark, j)`
27+ `ship` - ship to send the poke
29+ `app` - gall application to send the poke to
31+ `mark` - mark of data sent to the gall application
38+ Send an acknowledgment of receipt of a message so it's cleared from the ship's queue
40+ `eventId` - id of the event to acknowledge
45+ returns the sseclient object
48+`subscribe(ship, app, path)`
50+ `ship` - ship on which the gall application lives
52+ `app` - gall application to subscribe to
54+ `path` - path to subscribe on
57+Below is a simple script to send a message and subscribe to a chat channel. The specifics require an understanding of the `chat-store` and `chat-hook` interfaces.
59+Even without experience with python this should be pretty readable.
70+zod = urlock.Urlock("http://localhost:8080", "lidlut-tabwed-pillex-ridrup")
72+s = zod.subscribe("zod", "chat-store", "/mailbox/~/~zod/mc")
76+s = baseconvert.base(random.getrandbits(128), 10, 32, string=True).lower()
77+uid = '0v' + '.'.join(s[i:i+5] for i in range(0, len(s), 5))[::-1]
79+p = zod.poke("zod", "chat-hook", "json", {"message": {"path": "/~/~zod/mc",
80+ "envelope": {"uid": uid,
83+ "when": int(time.time() * 1000),
84+ "letter": {"text": "hello world!"}}}})
87+for m in pipe.events():
89+ dumper.dump(zod.ack(int(m.id)))
92+After the imports, instantiating the Urlock class with the address of the running ship and the `+code` from the ship. This code should not be shared. The one used here is for fakezods.
95+zod = urlock.Urlock("http://localhost:8080", "lidlut-tabwed-pillex-ridrup")
98+Next we connect to the ship and set up a subscription to chat-store
102+s = zod.subscribe("zod", "chat-store", "/mailbox/~/~zod/mc")
105+After this we get the SSE pipe that all responses will arrive on.
108+pipe = zod.sse_pipe()
111+Next comes some setup for specific implementation details of `chat-hook` and a `poke` is sent to create a new chat message.
114+s = baseconvert.base(random.getrandbits(128), 10, 32, string=True).lower()
115+uid = '0v' + '.'.join(s[i:i+5] for i in range(0, len(s), 5))[::-1]
117+p = zod.poke("zod", "chat-hook", "json", {"message": {"path": "/~/~zod/mc",
118+ "envelope": {"uid": uid,
121+ "when": int(time.time() * 1000),
122+ "letter": {"text": "hello world!"}}}})
125+Finally, the loop here is used to read messages from the sse pipe and send back an acknowledgment. This is important to clear the queue on the ship.
128+for m in pipe.events():
130+ dumper.dump(zod.ack(int(m.id)))