Skip to content

Commit 9676e41

Browse files
committed
docs(readme): add usage guidance
1 parent d20f877 commit 9676e41

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,48 @@ This is the Python client SDK to interact with the Mitosis API. It provides a co
44

55
See the [Mitosis documentation](https://docs.stack.rs/mitosis) and [Mitosis repository](https://github.com/stack-rs/mitosis) for more details.
66

7-
Use `uv add pynetmito` to add this package to your project.
7+
## Usage
8+
9+
Install the package with pip
10+
11+
```bash
12+
pip install pynetmito
13+
```
14+
15+
Or if you are using [uv](https://docs.astral.sh/uv/), you can add it to your project with:
16+
17+
```bash
18+
uv add pynetmito
19+
```
20+
21+
Now let's see a simple example of how to use the SDK:
22+
23+
```python
24+
from pynetmito import MitoHttpClient
25+
coordinator_addr = "http://127.0.0.1:5000" # The coordinator address of the mitosis backend service
26+
c = MitoHttpClient(coordinator_addr)
27+
c.connect(user="your-user-name", password="your-password")
28+
29+
# Now you can use the client to submit tasks
30+
with open("orig.txt", "w") as f:
31+
f.write("hello world")
32+
c.upload_attachment(Path("orig.txt"), key="some-remote-text-file/in-object-storage/log.txt")
33+
34+
# Specify the task with attachment
35+
attachment = RemoteResourceDownload(
36+
remote_file=RemoteResource.attachment("some-remote-text-file/in-object-storage/log.txt"), local_path=Path("test.txt")
37+
)
38+
task_spec = TaskSpec(args=["echo", "$MITO_RESOURCE/test.txt"], resources=[attachment], terminal_output=True)
39+
args = SubmitTaskReq(group_name=c.username, task_spec=task_spec)
40+
r = c.user_submit_task(args) # This will return a SubmitTaskResp object (with uuid to identify the task)
41+
res = c.get_task_by_uuid(r.uuid) # You can use the uuid to get the task status and result
42+
print(res)
43+
44+
# To download the terminal output of the task
45+
c.download_artifact(
46+
r.uuid,
47+
content_type=ArtifactContentType.STD_LOG,
48+
local_path=Path("new.txt"),
49+
)
50+
51+
```

0 commit comments

Comments
 (0)