Skip to main content

🐍 | Python library for RunPod API and serverless worker SDK.

Project description

RunPod | Python Library

PyPI Package   Downloads

CI | Code Quality   CI | Unit Tests   CI | CodeQL

Official Python library for RunPod API & SDK.

Table of Contents

Installation

# Install the latest release version
pip install runpod

# Install the latest development version (main branch)
pip install git+https://github.com/runpod/runpod-python.git

SDK - Serverless Worker

This python package can also be used to create a serverless worker that can be deployed to RunPod as a custom endpoint API.

Quick Start

Create an python script in your project that contains your model definition and the RunPod worker start code. Run this python code as your default container start command:

# my_worker.py

import runpod

def is_even(job):

    job_input = job["input"]
    the_number = job_input["number"]

    if not isinstance(the_number, int):
        return {"error": "Silly human, you need to pass an integer."}

    if the_number % 2 == 0:
        return True

    return False

runpod.serverless.start({"handler": is_even})

Make sure that this file is ran when your container starts. This can be accomplished by calling it in the docker command when you setup a template at runpod.io/console/serverless/user/templates or by setting it as the default command in your Dockerfile.

See our blog post for creating a basic Serverless API, or view the details docs for more information.

Local Test Worker

You can also test your worker locally before deploying it to RunPod. This is useful for debugging and testing.

python my_worker.py --rp_serve_api

API Language Library

When interacting with the RunPod API you can use this library to make requests to the API.

import runpod

runpod.api_key = "your_runpod_api_key_found_under_settings"

Endpoints

You can interact with RunPod endpoints via a run or run_sync method.

endpoint = runpod.Endpoint("ENDPOINT_ID")

run_request = endpoint.run(
    {"your_model_input_key": "your_model_input_value"}
)

# Check the status of the endpoint run request
print(run_request.status())

# Get the output of the endpoint run request, blocking until the endpoint run is complete.
print(run_request.output())
endpoint = runpod.Endpoint("ENDPOINT_ID")

run_request = endpoint.run_sync(
    {"your_model_input_key": "your_model_input_value"}
)

# Returns the job results if completed within 90 seconds, otherwise, returns the job status.
print(run_request )

GPU Pod Control

import runpod

runpod.api_key = "your_runpod_api_key_found_under_settings"

# Create a pod
pod = runpod.create_pod("test", "runpod/stack", "NVIDIA GeForce RTX 3070")

# Stop the pod
runpod.stop_pod(pod.id)

# Start the pod
runpod.start_pod(pod.id)

# Terminate the pod
runpod.terminate_pod(pod.id)

Directory

.
├── docs               # Documentation
├── runpod             # Package source code   ├── endpoint       # Language library - Endpoints   └── serverless     # SDK - Serverless Worker
└── tests              # Package tests

Community and Contributing

We welcome both pull requests and issues on GitHub. Bug fixes and new features are encouraged.

Discord Banner 2

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

runpod-0.10.0.tar.gz (64.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

runpod-0.10.0-py3-none-any.whl (39.6 kB view details)

Uploaded Python 3

File details

Details for the file runpod-0.10.0.tar.gz.

File metadata

  • Download URL: runpod-0.10.0.tar.gz
  • Upload date:
  • Size: 64.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for runpod-0.10.0.tar.gz
Algorithm Hash digest
SHA256 7cdef78648bf2b590c650d9dc57e88d63a7148de66a55f36b8111058c01ac586
MD5 fb30f3b6eb78ea64b79fd14f8453385b
BLAKE2b-256 b9f3ac6321be8de3791150b914c6969f2bb4bad27d649ceaaaab8a96fb738929

See more details on using hashes here.

File details

Details for the file runpod-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: runpod-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 39.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for runpod-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2fef5409411f0a268d472a73dc6dff3eae43a9e8ef72f6e686a8f60bf899320f
MD5 bce53740b2c888a6fe940bb9abefdec2
BLAKE2b-256 08d30f300e6611cb8a365425a3b4f8addbd0383f8beb447eab08e67ed4954ec2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page