Skip to content

Commit

Permalink
Merge pull request #37 from n0-computer/arqu/python
Browse files Browse the repository at this point in the history
feat(py): added basic example
  • Loading branch information
Arqu committed Oct 9, 2023
2 parents a077cd9 + bb048be commit fede48a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,7 @@ docs/_build/
.python-version

# Go
go/iroh-node-go

go/iroh-node-go
# Python
python/iroh-data
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ wheel for linux use:
docker run --rm -v $(pwd):/mnt -w /mnt quay.io/pypa/manylinux2014_x86_64 /mnt/build-wheel.sh
```

### Example

- Make sure the `iroh` is installed `pip install iroh`
- Run with `python3 main.py --help`

## Go

### Running
Expand Down
44 changes: 44 additions & 0 deletions python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import iroh

import argparse
import os
import time

IROH_DATA_DIR = "./iroh-data"

if __name__ == "__main__":

# parse arguments
parser = argparse.ArgumentParser(description='Python Iroh Node Demo')
parser.add_argument('--ticket', type=str, help='ticket to join a document')

args = parser.parse_args()

if not args.ticket:
print("Please provide a ticket to join a document")
exit()

# create iroh data dir if it does not exists
if not os.path.exists(IROH_DATA_DIR):
os.mkdir(IROH_DATA_DIR)

# create iroh node
node = iroh.IrohNode(IROH_DATA_DIR)
print("Started Iroh node: {}".format(node.node_id()))

# join doc
doc_ticket = iroh.DocTicket.from_string(args.ticket)
doc = node.doc_join(doc_ticket)
print("Joined doc: {}".format(doc.id()))

# sync & print
print("Waiting 5 seconds to let stuff sync...")
time.sleep(5)
keys = doc.keys()
print("Data:")
for key in keys:
content = doc.get_content_bytes(key)
print("{} : {} (hash: {})".format(key.key(), content.decode("utf8"), key.hash().to_string()))



1 change: 1 addition & 0 deletions python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
iroh==0.2.0

0 comments on commit fede48a

Please sign in to comment.