Skip to content

Commit da7bda5

Browse files
committed
Add mkdocs
1 parent 3165457 commit da7bda5

21 files changed

Lines changed: 2173 additions & 11 deletions

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
***
1+
---
22

33
name: Bug report
44
about: Create a report to help us improve
55
title: ''
66
labels: ''
77
assignees: ''
88

9-
***
9+
---
1010

1111
**Describe the bug**
1212
A clear and concise description of what the bug is.
@@ -27,16 +27,16 @@ If applicable, add screenshots to help explain your problem.
2727

2828
**Desktop (please complete the following information):**
2929

30-
* OS: \[e.g. iOS]
31-
* Browser \[e.g. chrome, safari]
32-
* Version \[e.g. 22]
30+
- OS: \[e.g. iOS]
31+
- Browser \[e.g. chrome, safari]
32+
- Version \[e.g. 22]
3333

3434
**Smartphone (please complete the following information):**
3535

36-
* Device: \[e.g. iPhone6]
37-
* OS: \[e.g. iOS8.1]
38-
* Browser \[e.g. stock browser, safari]
39-
* Version \[e.g. 22]
36+
- Device: \[e.g. iPhone6]
37+
- OS: \[e.g. iOS8.1]
38+
- Browser \[e.g. stock browser, safari]
39+
- Version \[e.g. 22]
4040

4141
**Additional context**
4242
Add any other context about the problem here.

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
***
1+
---
22

33
name: Feature request
44
about: Suggest an idea for this project
55
title: ''
66
labels: ''
77
assignees: ''
88

9-
***
9+
---
1010

1111
**Is your feature request related to a problem? Please describe.**
1212
A clear and concise description of what the problem is. Ex. I'm always frustrated when \[...]

.github/workflows/deploy-docs.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Deploy Documentation to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'docs/**'
9+
- '.github/workflows/deploy-docs.yml'
10+
11+
permissions:
12+
contents: read
13+
pages: write
14+
id-token: write
15+
16+
concurrency:
17+
group: "pages"
18+
cancel-in-progress: false
19+
20+
jobs:
21+
deploy:
22+
environment:
23+
name: github-pages
24+
url: ${{ steps.deployment.outputs.page_url }}
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Set up Python
30+
uses: actions/setup-python@v4
31+
with:
32+
python-version: '3.11'
33+
34+
- name: Install dependencies
35+
working-directory: ./docs
36+
run: |
37+
pip install -r requirements.txt
38+
39+
- name: Build MkDocs
40+
working-directory: ./docs
41+
run: mkdocs build
42+
43+
- name: Upload artifact
44+
uses: actions/upload-pages-artifact@v2
45+
with:
46+
path: './site'
47+
48+
- name: Deploy to GitHub Pages
49+
id: deployment
50+
uses: actions/deploy-pages@v2

docs/api/async-client.md

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
# AsyncZeroClient API Reference
2+
3+
## Overview
4+
5+
`AsyncZeroClient` is the asynchronous client for calling RPC methods with async/await support.
6+
7+
## Constructor
8+
9+
```python
10+
AsyncZeroClient(
11+
host: str,
12+
port: int,
13+
default_timeout: int = 2000,
14+
encoder: Type[Encoder] = GenericEncoder,
15+
protocol: Type[AsyncZeroClientProtocol] = AsyncZMQClient,
16+
pool_size: int = 50,
17+
)
18+
```
19+
20+
### Parameters
21+
22+
- **host** (str): Server hostname or IP address.
23+
- **port** (int): Server port number.
24+
- **default_timeout** (int): Default timeout for calls in milliseconds. Default: 2000
25+
- **encoder** (Encoder): Message encoder matching server. Default: Msgspec
26+
- **protocol** (AsyncClientProtocol): Async communication protocol. Default: ZeroMQ
27+
- `zero.protocols.zeromq.AsyncZeroMQClient` - ZeroMQ (default)
28+
- `zero.protocols.tcp.AsyncTCPClient` - Raw TCP
29+
- **pool_size** (int): Connection pool size for reusing connections. Default: 50
30+
31+
### Example
32+
33+
```python
34+
import asyncio
35+
from zero import AsyncZeroClient
36+
from zero.protocols.tcp import AsyncTCPClient
37+
38+
async def main():
39+
client = AsyncZeroClient(
40+
host="192.168.1.100",
41+
port=5559,
42+
protocol=AsyncTCPClient
43+
)
44+
45+
asyncio.run(main())
46+
```
47+
48+
## Methods
49+
50+
### call
51+
52+
Asynchronously call an RPC method on the server.
53+
54+
```python
55+
async def call(
56+
rpc_func_name: str,
57+
msg: AllowedType,
58+
timeout: Optional[int] = None,
59+
return_type: Optional[Type[T]] = None,
60+
) -> T
61+
```
62+
63+
**Parameters:**
64+
65+
- **rpc_func_name** (str): Name of the RPC method to call
66+
- **msg** (Any): Argument to pass to the method
67+
- **timeout** (int): Timeout for the call in milliseconds. Optional. Defaults to `default_timeout`.
68+
- **return_type** (Type): Expected return type for type conversion. Optional.
69+
70+
**Returns:** Response from the server (awaitable)
71+
72+
**Raises:** Exception if server returns error
73+
74+
## Usage Examples
75+
76+
### Basic Async Call
77+
78+
```python
79+
import asyncio
80+
from zero import AsyncZeroClient
81+
82+
async def main():
83+
client = AsyncZeroClient("localhost", 5559)
84+
result = await client.call("hello_world", None)
85+
print(result)
86+
87+
asyncio.run(main())
88+
```
89+
90+
### Multiple Sequential Calls
91+
92+
```python
93+
import asyncio
94+
from zero import AsyncZeroClient
95+
96+
async def main():
97+
client = AsyncZeroClient("localhost", 5559)
98+
99+
result1 = await client.call("method1", "data1")
100+
result2 = await client.call("method2", result1)
101+
result3 = await client.call("method3", result2)
102+
103+
print(result3)
104+
105+
asyncio.run(main())
106+
```
107+
108+
### Concurrent Requests
109+
110+
```python
111+
import asyncio
112+
from zero import AsyncZeroClient
113+
114+
async def main():
115+
client = AsyncZeroClient("localhost", 5559)
116+
117+
# Run 10 requests concurrently
118+
results = await asyncio.gather(
119+
*[client.call("process", i) for i in range(10)]
120+
)
121+
122+
print(f"Completed {len(results)} requests")
123+
124+
asyncio.run(main())
125+
```
126+
127+
### With Type Conversion
128+
129+
```python
130+
import asyncio
131+
from zero import AsyncZeroClient
132+
from dataclasses import dataclass
133+
134+
@dataclass
135+
class User:
136+
id: int
137+
name: str
138+
email: str
139+
140+
async def main():
141+
client = AsyncZeroClient("localhost", 5559)
142+
143+
user = await client.call("get_user", 1, return_type=User)
144+
print(f"User: {user.name} <{user.email}>")
145+
146+
asyncio.run(main())
147+
```
148+
149+
## Protocol Selection
150+
151+
### ZeroMQ (Default)
152+
153+
```python
154+
client = AsyncZeroClient("localhost", 5559)
155+
# Uses ZeroMQ by default
156+
```
157+
158+
### TCP (Better Performance)
159+
160+
```python
161+
from zero.protocols.tcp import AsyncTCPClient
162+
163+
client = AsyncZeroClient(
164+
"localhost", 5559,
165+
protocol=AsyncTCPClient
166+
)
167+
```
168+
169+
## Connection Pooling
170+
171+
```python
172+
import asyncio
173+
from zero import AsyncZeroClient
174+
175+
async def main():
176+
# Single client handles multiple concurrent requests
177+
client = AsyncZeroClient("localhost", 5559)
178+
179+
tasks = [
180+
client.call("method", f"data_{i}")
181+
for i in range(100)
182+
]
183+
184+
results = await asyncio.gather(*tasks)
185+
print(f"Completed {len(results)} requests")
186+
187+
asyncio.run(main())
188+
```
189+
190+
## Best Practices
191+
192+
**DO:**
193+
194+
- Use `asyncio.gather()` for concurrent requests
195+
- Reuse client instance across multiple calls
196+
- Use `asyncio.wait_for()` for timeouts
197+
- Handle `asyncio.TimeoutError` and `ConnectionError`
198+
- Use `return_type` for type conversion
199+
200+
**DON'T:**
201+
202+
- Create new client for each call
203+
- Block the event loop with sync operations
204+
- Use sync `ZeroClient` in async code
205+
206+
## Next Steps
207+
208+
- [ZeroClient](client.md) - Synchronous client
209+
- [Guides - Async/Await](../guides/async-await.md) - Detailed async patterns
210+
- [Guides - Code Generation](../guides/code-generation.md) - Generate async clients

0 commit comments

Comments
 (0)