Skip to main content

Official Python library for RunPod API & SDK.

Project description

RunPod | Python Library

PyPI Package   Downloads

CI | Code Quality   CI | Unit Tests

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:

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.

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.9.12.tar.gz (62.8 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.9.12-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for runpod-0.9.12.tar.gz
Algorithm Hash digest
SHA256 8419559e4823b6798a8c7c7e89b58f034c15a47476f1c07525b1dba5d6323f9c
MD5 3e2c61d94d0a19426b3c31f2eaf9a86f
BLAKE2b-256 7242511eb554e2425c27424b081c4ebb0f76f07665f6d00b1284d2157b331e48

See more details on using hashes here.

File details

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

File metadata

  • Download URL: runpod-0.9.12-py3-none-any.whl
  • Upload date:
  • Size: 37.3 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.9.12-py3-none-any.whl
Algorithm Hash digest
SHA256 16d3ee46e4dd6a8ea72f58417b7ed8160cb2fad57d4d2a84f418172750898023
MD5 81a8b80c8c1c76c99f9f5f44b33ec086
BLAKE2b-256 e4569601da7b17b9ecd86612ed162ed449135fa5deae13b25d1404fd4bc38a49

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