Skip to content

Commit 10f6446

Browse files
committed
docs(python): python bindings go brrrrr
1 parent 77b7624 commit 10f6446

File tree

16 files changed

+248
-20
lines changed

16 files changed

+248
-20
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import iroh
2+
3+
IROH_DATA_DIR = "./iroh-data"
4+
5+
node = iroh.IrohNode(IROH_DATA_DIR)
6+
print("Started Iroh node: {}".format(node.node_id()))
7+
8+
author = node.author_new()
9+
print("Created author: {}".format(author.to_string()))
10+
11+
authors = node.author_list()
12+
for auth in authors:
13+
print("Author: {}".format(auth.to_string()))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import iroh
2+
3+
IROH_DATA_DIR = "./iroh-data"
4+
5+
node = iroh.IrohNode(IROH_DATA_DIR)
6+
print("Started Iroh node: {}".format(node.node_id()))
7+
8+
author = node.author_new()
9+
print("Created author: {}".format(author.to_string()))
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import iroh
22

3-
node = iroh.node()
4-
author = node.create_author()
5-
doc = node.create_doc()
3+
IROH_DATA_DIR = "./iroh-data"
64

7-
doc.set_bytes(author, bytes("foo", "utf8"), bytes("bar", "utf8"))
5+
node = iroh.IrohNode(IROH_DATA_DIR)
6+
print("Started Iroh node: {}".format(node.node_id()))
87

9-
doc.get_bytes(bytes("foo", "utf8"))
8+
author = node.author_new()
9+
print("Created author: {}".format(author.to_string()))
10+
11+
doc = node.doc_new()
12+
print("Created doc: {}".format(doc.id()))
13+
14+
hash = doc.set_bytes(author, bytes("foo", "utf8"), bytes("bar", "utf8"))
15+
print("Inserted: {}".format(hash.to_string()))
16+
17+
# FIXME: this doesn't work yet
18+
# content = doc.get_content_bytes(hash)
19+
# print("Got content: {}".format(content.decode("utf8")))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import iroh
2+
3+
IROH_DATA_DIR = "./iroh-data"
4+
5+
# you'll need to get a ticket from somewhere, see the `doc share` command documentation
6+
# for details. This ticket will fail to join, but is a valid ticket.
7+
TICKET_STRING = "sdx7wazju2rysqydgfpmhqkrluc5lbcuainravjipwmbl7r3k3uqcigncyopdcnooufnteu5vuatpzhoqrml35ifgyuozr6kwhjiz4jxyaaqcbiajbmsainmsmbqcjqaibavg5hiaaaaaaaaaaabad47sebqbqfiiqzkzeydadakqrckvsjqgajgabaecu3u5aaaaaaaaaaaaeagt6iqg"
8+
9+
node = iroh.IrohNode(IROH_DATA_DIR)
10+
print("Started Iroh node: {}".format(node.node_id()))
11+
12+
doc_ticket = iroh.DocTicket.from_string(TICKET_STRING)
13+
doc = node.doc_join(doc_ticket)
14+
print("Joined doc: {}".format(doc.id()))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import iroh
2+
3+
IROH_DATA_DIR = "./iroh-data"
4+
5+
node = iroh.IrohNode(IROH_DATA_DIR)
6+
print("Started Iroh node: {}".format(node.node_id()))
7+
8+
author = node.author_new()
9+
print("Created author: {}".format(author.to_string()))
10+
11+
doc = node.doc_new()
12+
print("Created doc: {}".format(doc.id()))
13+
14+
for i, key in enumerate(['a', 'b', 'c']):
15+
doc.set_bytes(author, bytes(key, "utf8"), bytes(str(i), "utf8"))
16+
17+
keys = doc.keys()
18+
print("Keys:")
19+
for key in keys:
20+
content = doc.get_content_bytes(key)
21+
print("{} : {} (hash: {})".format(key.key(), content.decode("utf8"), key.hash().to_string()))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import iroh
2+
3+
IROH_DATA_DIR = "./iroh-data"
4+
5+
node = iroh.IrohNode(IROH_DATA_DIR)
6+
print("Started Iroh node: {}".format(node.node_id()))
7+
8+
author = node.author_new()
9+
print("Created author: {}".format(author.to_string()))
10+
11+
doc = node.doc_new()
12+
print("Created doc: {}".format(doc.id()))
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import iroh
22

3-
node = iroh.node()
4-
author = node.create_author()
5-
doc = node.create_doc()
3+
IROH_DATA_DIR = "./iroh-data"
64

7-
doc.set_bytes(author, bytes("foo", "utf8"), bytes("bar", "utf8"))
5+
node = iroh.IrohNode(IROH_DATA_DIR)
6+
print("Started Iroh node: {}".format(node.node_id()))
87

9-
doc.get_bytes(bytes("foo", "utf8"))
8+
author = node.author_new()
9+
print("Created author: {}".format(author.to_string()))
10+
11+
doc = node.doc_new()
12+
print("Created doc: {}".format(doc.id()))
13+
14+
hash = doc.set_bytes(author, bytes("foo", "utf8"), bytes("bar", "utf8"))
15+
print("Inserted: {}".format(hash.to_string()))
16+
17+
# FIXME: this doesn't work yet
18+
# content = doc.get_content_bytes(hash)
19+
# print("Got content: {}".format(content.decode("utf8")))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import iroh
2+
3+
IROH_DATA_DIR = "./iroh-data"
4+
5+
node = iroh.IrohNode(IROH_DATA_DIR)
6+
print("Started Iroh node: {}".format(node.node_id()))
7+
8+
author = node.author_new()
9+
print("Created author: {}".format(author.to_string()))
10+
11+
doc = node.doc_new()
12+
print("Created doc: {}".format(doc.id()))
13+
14+
ticket = doc.share_write()
15+
print("Write-Access Ticket: {}".format(ticket.to_string()))

src/app/docs/commands/author-list/page.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ i3vpd4e7coeonwv6otni36bdux73opig5du6zjekvnl3c64gn4ua
2727
wkl4cgrykxvcvr6pjnbvymrzm7h4je7d4ztszp35xfnk2rnflcxq
2828
```
2929

30+
```python {{ title: 'python' }}
31+
import iroh
32+
33+
IROH_DATA_DIR = "./iroh-data"
34+
35+
node = iroh.IrohNode(IROH_DATA_DIR)
36+
print("Started Iroh node: {}".format(node.node_id()))
37+
38+
author = node.author_new()
39+
print("Created author: {}".format(author.to_string()))
40+
41+
authors = node.author_list()
42+
for auth in authors:
43+
print("Author: {}".format(auth.to_string()))
44+
45+
```
46+
3047
```swift {{ title: 'go' }}
3148
package main
3249

src/app/docs/commands/author-new/page.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ author:2rkuvpk4…
3737
>
3838
```
3939

40+
```python {{ title: 'python' }}
41+
import iroh
42+
43+
IROH_DATA_DIR = "./iroh-data"
44+
45+
node = iroh.IrohNode(IROH_DATA_DIR)
46+
print("Started Iroh node: {}".format(node.node_id()))
47+
48+
author = node.author_new()
49+
print("Created author: {}".format(author.to_string()))
50+
51+
```
52+
4053
```swift {{ title: 'go' }}
4154
package main
4255

0 commit comments

Comments
 (0)