Skip to content

Commit f8f832a

Browse files
authored
Add Python client docs (#1519)
1 parent 4a86780 commit f8f832a

File tree

5 files changed

+366
-16
lines changed

5 files changed

+366
-16
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ aws-clear-bucket:
147147
tools:
148148
@go get -u -v golang.org/x/lint/golint
149149
@go get -u -v github.com/VojtechVitek/rerun/cmd/rerun
150-
@python3 -m pip install black
150+
@python3 -m pip install black 'pydoc-markdown>=3.0.0,<4.0.0'
151151
@if [[ "$$OSTYPE" == "darwin"* ]]; then brew install parallel; elif [[ "$$OSTYPE" == "linux"* ]]; then sudo apt-get install -y parallel; else echo "your operating system is not supported"; fi
152152

153153
format:

dev/generate_python_client_md.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
# Copyright 2020 Cortex Labs, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
set -euo pipefail
19+
20+
if [[ "$OSTYPE" != "linux"* ]]; then
21+
echo "error: this script is only designed to run on linux"
22+
exit 1
23+
fi
24+
25+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"
26+
27+
pip3 uninstall -y cortex
28+
29+
cd $ROOT/pkg/workloads/cortex/client
30+
31+
pip3 install -e .
32+
33+
pydoc-markdown -m cortex -m cortex.client --render-toc > $ROOT/docs/miscellaneous/python_client.md
34+
35+
# title
36+
sed -i "s/# Table of Contents/# Python client\n\n_WARNING: you are on the master branch, please refer to the docs on the branch that matches your \`cortex version\`_/g" $ROOT/docs/miscellaneous/python_client.md
37+
38+
# delete links
39+
sed -i "/<a name=/d" $ROOT/docs/miscellaneous/python_client.md
40+
41+
# delete unnecessary section headers
42+
sed -i "/_](#cortex\.client\.Client\.__init__)/d" $ROOT/docs/miscellaneous/python_client.md
43+
sed -i "/\* \[Client](#cortex\.client\.Client)/d" $ROOT/docs/miscellaneous/python_client.md
44+
# fix section link/header
45+
sed -i "s/\* \[cortex\.client](#cortex\.client)/\* [cortex\.client\.Client](#cortex-client-client)/g" $ROOT/docs/miscellaneous/python_client.md
46+
sed -i "s/# cortex\.client/# cortex\.client\.Client/g" $ROOT/docs/miscellaneous/python_client.md
47+
# delete unnecessary section body
48+
sed -i "/# cortex.client.Client/,/## deploy/{//!d}" $ROOT/docs/miscellaneous/python_client.md
49+
sed -i "s/# cortex.client.Client/# cortex.client.Client\n/g" $ROOT/docs/miscellaneous/python_client.md
50+
51+
# fix table of contents links
52+
sed -i "s/](#cortex\./](#/g" $ROOT/docs/miscellaneous/python_client.md
53+
sed -i "s/](#client\.Client\./](#/g" $ROOT/docs/miscellaneous/python_client.md
54+
55+
# indentdation
56+
sed -i "s/ \* / \* /g" $ROOT/docs/miscellaneous/python_client.md
57+
sed -i "s/#### /## /g" $ROOT/docs/miscellaneous/python_client.md
58+
59+
# whitespace
60+
sed -i 's/[[:space:]]*$//' $ROOT/docs/miscellaneous/python_client.md
61+
truncate -s -1 $ROOT/docs/miscellaneous/python_client.md
62+
63+
pip3 uninstall -y cortex
64+
65+
cat << EOF
66+
67+
#### MANUAL EDITS REQUIRED ####
68+
69+
- Copy the docstring for \`client(env: str)\` in pkg/workloads/cortex/client/__init__.py into the generated docs and unindent
70+
71+
Then check the diff
72+
EOF
73+
74+
# TODO automate? test on mac?
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
# Python client
2+
3+
_WARNING: you are on the master branch, please refer to the docs on the branch that matches your `cortex version`_
4+
5+
* [cortex](#cortex)
6+
* [client](#client)
7+
* [local\_client](#local_client)
8+
* [cluster\_client](#cluster_client)
9+
* [env\_list](#env_list)
10+
* [env\_delete](#env_delete)
11+
* [cortex.client.Client](#cortex-client-client)
12+
* [deploy](#deploy)
13+
* [get\_api](#get_api)
14+
* [list\_apis](#list_apis)
15+
* [get\_job](#get_job)
16+
* [refresh](#refresh)
17+
* [delete\_api](#delete_api)
18+
* [stop\_job](#stop_job)
19+
* [stream\_api\_logs](#stream_api_logs)
20+
* [stream\_job\_logs](#stream_job_logs)
21+
22+
# cortex
23+
24+
## client
25+
26+
```python
27+
client(env: str)
28+
```
29+
30+
Initialize a client based on the specified environment.
31+
32+
To deploy and manage APIs on a new cluster:
33+
34+
1. Spin up a cluster using the CLI command `cortex cluster up`.
35+
An environment named "aws" will be created once the cluster is ready.
36+
2. Initialize your client:
37+
38+
```python
39+
import cortex
40+
c = cortex.client("aws")
41+
c.deploy("./cortex.yaml")
42+
```
43+
44+
To deploy and manage APIs on an existing cluster:
45+
46+
1. Use the command `cortex cluster info` to get the Operator Endpoint.
47+
2. Configure a client to your cluster:
48+
49+
```python
50+
import cortex
51+
c = cortex.cluster_client("aws", operator_endpoint, aws_access_key_id, aws_secret_access_key)
52+
c.deploy("./cortex.yaml")
53+
```
54+
55+
To deploy and manage APIs locally:
56+
57+
```python
58+
import cortex
59+
c = cortex.client("local")
60+
c.deploy("./cortex.yaml")
61+
```
62+
63+
**Arguments**:
64+
65+
- `env` - Name of the environment to use.
66+
67+
68+
**Returns**:
69+
70+
Cortex client that can be used to deploy and manage APIs in the specified environment.
71+
72+
## local\_client
73+
74+
```python
75+
local_client(aws_access_key_id: str, aws_secret_access_key: str, aws_region: str) -> Client
76+
```
77+
78+
Initialize a client to deploy and manage APIs locally.
79+
80+
The specified AWS credentials will be used by the CLI to download models
81+
from S3 and authenticate to ECR, and will be set in your Predictor.
82+
83+
**Arguments**:
84+
85+
- `aws_access_key_id` - AWS access key ID.
86+
- `aws_secret_access_key` - AWS secret access key.
87+
- `aws_region` - AWS region.
88+
89+
90+
**Returns**:
91+
92+
Cortex client that can be used to deploy and manage APIs locally.
93+
94+
## cluster\_client
95+
96+
```python
97+
cluster_client(name: str, operator_endpoint: str, aws_access_key_id: str, aws_secret_access_key: str) -> Client
98+
```
99+
100+
Create a new environment to connect to an existing Cortex Cluster, and initialize a client to deploy and manage APIs on that cluster.
101+
102+
**Arguments**:
103+
104+
- `name` - Name of the environment to create.
105+
- `operator_endpoint` - The endpoint for the operator of your Cortex Cluster. You can get this endpoint by running the CLI command `cortex cluster info`.
106+
- `aws_access_key_id` - AWS access key ID.
107+
- `aws_secret_access_key` - AWS secret access key.
108+
109+
110+
**Returns**:
111+
112+
Cortex client that can be used to deploy and manage APIs on a Cortex Cluster.
113+
114+
## env\_list
115+
116+
```python
117+
env_list() -> list
118+
```
119+
120+
List all environments configured on this machine.
121+
122+
## env\_delete
123+
124+
```python
125+
env_delete(name: str)
126+
```
127+
128+
Delete an environment configured on this machine.
129+
130+
**Arguments**:
131+
132+
- `name` - Name of the environment to delete.
133+
134+
# cortex.client.Client
135+
136+
## deploy
137+
138+
```python
139+
| deploy(config_file: str, force: bool = False, wait: bool = False) -> list
140+
```
141+
142+
Deploy or update APIs specified in the config_file.
143+
144+
**Arguments**:
145+
146+
- `config_file` - Local path to a yaml file defining Cortex APIs.
147+
- `force` - Override any in-progress api updates.
148+
- `wait` - Streams logs until the APIs are ready.
149+
150+
151+
**Returns**:
152+
153+
Deployment status, API specification, and endpoint for each API.
154+
155+
## get\_api
156+
157+
```python
158+
| get_api(api_name: str) -> dict
159+
```
160+
161+
Get information about an API.
162+
163+
**Arguments**:
164+
165+
- `api_name` - Name of the API.
166+
167+
168+
**Returns**:
169+
170+
Information about the API, including the API specification, endpoint, status, and metrics (if applicable).
171+
172+
## list\_apis
173+
174+
```python
175+
| list_apis() -> list
176+
```
177+
178+
List all APIs in the environment.
179+
180+
**Returns**:
181+
182+
List of APIs, including information such as the API specification, endpoint, status, and metrics (if applicable).
183+
184+
## get\_job
185+
186+
```python
187+
| get_job(api_name: str, job_id: str) -> dict
188+
```
189+
190+
Get information about a submitted job.
191+
192+
**Arguments**:
193+
194+
- `api_name` - Name of the Batch API.
195+
- `job_id` - Job ID.
196+
197+
198+
**Returns**:
199+
200+
Information about the job, including the job status, worker status, and job progress.
201+
202+
## refresh
203+
204+
```python
205+
| refresh(api_name: str, force: bool = False)
206+
```
207+
208+
Restart all of the replicas for a Realtime API without downtime.
209+
210+
**Arguments**:
211+
212+
- `api_name` - Name of the API to refresh.
213+
- `force` - Override an already in-progress API update.
214+
215+
## delete\_api
216+
217+
```python
218+
| delete_api(api_name: str, keep_cache: bool = False)
219+
```
220+
221+
Delete an API.
222+
223+
**Arguments**:
224+
225+
- `api_name` - Name of the API to delete.
226+
- `keep_cache` - Whether to retain the cached data for this API.
227+
228+
## stop\_job
229+
230+
```python
231+
| stop_job(api_name: str, job_id: str, keep_cache: bool = False)
232+
```
233+
234+
Stop a running job.
235+
236+
**Arguments**:
237+
238+
- `api_name` - Name of the Batch API.
239+
- `job_id` - ID of the Job to stop.
240+
241+
## stream\_api\_logs
242+
243+
```python
244+
| stream_api_logs(api_name: str)
245+
```
246+
247+
Stream the logs of an API.
248+
249+
**Arguments**:
250+
251+
- `api_name` - Name of the API.
252+
253+
## stream\_job\_logs
254+
255+
```python
256+
| stream_job_logs(api_name: str, job_id: str)
257+
```
258+
259+
Stream the logs of a Job.
260+
261+
**Arguments**:
262+
263+
- `api_name` - Name of the Batch API.
264+
- `job_id` - Job ID.

docs/summary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
## Miscellaneous
4949

5050
* [CLI commands](miscellaneous/cli.md)
51+
* [Python client](miscellaneous/python_client.md)
5152
* [Environments](miscellaneous/environments.md)
5253
* [Architecture diagram](miscellaneous/architecture.md)
5354
* [Security](miscellaneous/security.md)

0 commit comments

Comments
 (0)