Skip to content

Commit ddffacd

Browse files
committed
Adds Python SDK
1 parent 9fd4632 commit ddffacd

File tree

10 files changed

+288
-0
lines changed

10 files changed

+288
-0
lines changed

docs/sdks/_category_.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "SDKs",
3+
"position": 6,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Work and manage your Pods, templates, Serverless, and more with the help of our SDKs."
7+
}
8+
}

docs/sdks/hello/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
api_key = "5YLEDXAQKUKF86DX487GVYNGX3GDVW81Q881N5A4"

docs/sdks/hello/test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import runpod
2+
3+
try:
4+
new_template = runpod.create_template(
5+
name="testing-02", image_name="runpod/base:0.4.4", is_serverless=True
6+
)
7+
8+
print(new_template)
9+
10+
new_endpoint = runpod.create_endpoint(
11+
name="test",
12+
template_id=new_template["id"],
13+
gpu_ids="AMPERE_16",
14+
workers_min=0,
15+
workers_max=1,
16+
)
17+
18+
print(new_endpoint)
19+
20+
except runpod.error.QueryError as err:
21+
print(err)
22+
print(err.query)

docs/sdks/overview.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Overview
3+
description: Overview of the SDKs
4+
sidebar_position: 1
5+
---
6+
7+
RunPod provides mutliple SDKs to interact with the RunPod API.
8+
9+
The SDKs are available in multiple languages and are open source.

docs/sdks/python/_category_.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Python",
3+
"position": 6,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Use the RunPod Python SDK."
7+
}
8+
}

docs/sdks/python/api.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: API
3+
---
4+
5+
## Get Endpoints
6+
7+
To fetch all available endpoints from the API, use the get_endpoints function.
8+
This function returns a list of endpoint configurations available for use.
9+
10+
```python
11+
import runpod
12+
13+
endpoints = runpod.get_endpoints()
14+
15+
print(endpoints)
16+
```
17+
18+
## Create Template
19+
20+
You can create a new template in RunPod by specifying the name and the Docker image to use.
21+
This is useful for setting up environments with pre-defined configurations.
22+
23+
```python
24+
import runpod
25+
26+
27+
try:
28+
29+
new_template = runpod.create_template(
30+
name="test",
31+
image_name="runpod/base:0.1.0"
32+
)
33+
34+
print(new_template)
35+
36+
except runpod.error.QueryError as err:
37+
print(err)
38+
print(err.query)
39+
```
40+
41+
## Create Endpoint
42+
43+
Creating an endpoint involves first creating a template and then setting up the endpoint with the template ID.
44+
You can specify GPU requirements, the number of workers, and other configurations.
45+
Your Template name must be unique.
46+
47+
```python
48+
import runpod
49+
50+
try:
51+
52+
new_template = runpod.create_template(
53+
name="test",
54+
image_name="runpod/base:0.4.4",
55+
is_serverless=True
56+
)
57+
58+
print(new_template)
59+
60+
new_endpoint = runpod.create_endpoint(
61+
name="test",
62+
template_id=new_template["id"],
63+
gpu_ids="AMPERE_16",
64+
workers_min=0,
65+
workers_max=1
66+
)
67+
68+
print(new_endpoint)
69+
70+
except runpod.error.QueryError as err:
71+
print(err)
72+
print(err.query)
73+
```
74+
75+
```json
76+
{'id': 'cx829zvv9e', 'name': 'testing-01', 'imageName': 'runpod/base:0.4.4', 'dockerArgs': '', 'containerDiskInGb': 10, 'volumeInGb': 0, 'volumeMountPath': '/workspace', 'ports': None, 'env': [], 'isServerless': True}
77+
{'id': '838j9id2xmmwew', 'name': 'test', 'templateId': 'cx829zvv9e', 'gpuIds': 'AMPERE_16', 'networkVolumeId': None, 'locations': None, 'idleTimeout': 5, 'scalerType': 'QUEUE_DELAY', 'scalerValue': 4, 'workersMin': 0, 'workersMax': 1}
78+
```

docs/sdks/python/endpoints.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: Endpoints
3+
---
4+
5+
## Run Sync
6+
7+
## Run
8+
9+
### Async Job requests
10+
11+
Example of calling an endpoint using asyncio.
12+
13+
## Health
14+
15+
Example of calling a Health Endpoint.
16+
17+
```python
18+
import runpod
19+
20+
endpoint = runpod.Endpoint("gwp4kx5yd3nur1")
21+
22+
endpoint_health = endpoint.health()
23+
24+
print(endpoint_health)
25+
```
26+
27+
## Streaming
28+
29+
Example of Streaming your Endpoint.
30+
31+
```python
32+
import runpod
33+
34+
endpoint = runpod.Endpoint("gwp4kx5yd3nur1")
35+
36+
run_request = endpoint.run({
37+
"input": {
38+
"mock_return": ["a", "b", "c", "d", "e", "f", "g"],
39+
"mock_delay": 1,
40+
}
41+
})
42+
43+
for output in run_request.stream():
44+
print(output)
45+
```

docs/sdks/python/installation.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Installation
3+
sidebar_position: 2
4+
---
5+
6+
The RunPod Python SDK supports Python 3.8 or greater.
7+
Using virtual environments are recommended.
8+
9+
## Install
10+
11+
```bash
12+
pip install runpod
13+
```

docs/sdks/python/overview.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: Overview
3+
sidebar_position: 1
4+
---
5+
6+
## Project structure
7+
8+
RunPod Serverless is a monorepo that contains multiple services.
9+
10+
```text
11+
.
12+
├── Dockerfile # Docker configuration
13+
├── LICENSE # License information
14+
├── README.md # Project documentation
15+
├── builder
16+
│ ├── requirements.txt # Dependencies
17+
│ └── setup.sh # Setup script
18+
└── src
19+
└── __init__.py # API key reference
20+
└── handler.py # Main handler code
21+
```
22+
23+
## Add your API key
24+
25+
In most cases, you'll add your `api_key` variable to the `__init__.py` file.
26+
27+
```python
28+
api_key = "YOUR_API_KEY"
29+
```
30+
31+
This file will be read upon every execution of your code.
32+
33+
Alternatively, you can set your API key in your environment variables.
34+
Use an environment variable and load it into your code.
35+
36+
```python
37+
import runpod
38+
import os
39+
40+
runpod.api_key = os.getenv("RUNPOD_API_KEY")
41+
```

docs/sdks/python/serverless.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: Serverless
3+
---
4+
5+
The Python SDK allows you to create Serverless Workers that are deployed to RunPod as custom Endpoints.
6+
7+
## Set your Endpoint Id
8+
9+
Pass your Endpoint Id on the `Endpoint` class.
10+
11+
```python
12+
import runpod
13+
14+
endpoint = runpod.Endpoint("YOUR_ENDPOINT_ID")
15+
```
16+
17+
This allows all calls to pass through your Endpoint Id with a valid API key.
18+
19+
## Run the Endpoint
20+
21+
Run the Endpoint with the either the asynchronous `run` or synchronous `run_sync` method.
22+
23+
Set your method call on the instances of the endpoint.
24+
`run` returns a Job Id.
25+
26+
```python
27+
import runpod
28+
29+
endpoint = runpod.Endpoint("YOUR_ENDPOINT_ID")
30+
31+
endpoint.run(
32+
{"input": "your custom prompt"}
33+
)
34+
```
35+
36+
---
37+
38+
Alternatively, use can set `run_sync` for synchronously requests.
39+
`run_sync` returns a dictionary of strings or any.
40+
41+
```python
42+
import runpod
43+
44+
endpoint = runpod.Endpoint("YOUR_ENDPOINT_ID")
45+
46+
endpoint.run_sync(
47+
{"input": "your custom prompt"}
48+
)
49+
```
50+
51+
You can also set a timeout on the `run_sync` request.
52+
The timeout is set in seconds.
53+
54+
```python
55+
import runpod
56+
57+
endpoint = runpod.Endpoint("YOUR_ENDPOINT_ID")
58+
59+
endpoint.run_sync(
60+
{"input": "your custom prompt"},
61+
timeout=60
62+
)
63+
```

0 commit comments

Comments
 (0)