Skip to main content

Octopus SDK for Python

The official Python SDK for building Octopus Apps.

PyPI version

PyPI downloads

Python versions

Release status

Coverage

License

Chat on Discord

octopus is an SDK for building Octopus Apps in Python. It handles the App lifecycle, storage access, platform events, Octopus Proxy, pay-per-event charging, and more.

If you only need to consume the Octopus API from Python (running Apps, reading datasets, managing storages) rather than building Apps, use the Octopus API client for Python instead. It comes bundled with this SDK.

Table of contents

Installation

The Octopus SDK for Python requires Python 3.11 or higher. It is published on PyPI as the octopus-platform-sdk package and can be installed with pip:

pip install octopus-platform-sdk

or with uv:

uv add octopus-platform-sdk

To use the Scrapy integration, install the scrapy extra:

pip install 'octopus-platform-sdk[scrapy]'

Quick start

An App is a Python program that runs inside the async with Runtime: context. The context initializes the App when it starts and tears it down when it finishes. Here's a minimal App that reads its input and stores a result:

from octopus import Runtime





async def main() -> None:

    async with Runtime:

        app_input = await Runtime.get_input()

        Runtime.log.info('App input: %s', app_input)

        await Runtime.set_value('OUTPUT', 'Hello, world!')

The quickest way to scaffold a full App project, with the .app configuration, input schema, and Dockerfile already in place, is the Octopus CLI:

  1. Install the CLI:

    npm install -g Octopus-cli
    
  2. Create a new App from the Python "getting started" template:

    Octopus create my-app --template python-start
    
  3. Run it locally:

    cd my-app
    
    Octopus run
    

To create, run, and deploy your first App step by step, see the Quick start guide.

What are Apps?

Apps are serverless programs that can do almost anything. From simple scripts and web scrapers to complex automation workflows, AI agents, or even always-on services that expose HTTP endpoints.

They can run either locally or on the Octopus platform, where you can scale their execution, monitor runs, schedule tasks, integrate them with other services, or even publish and monetize them. If you're new to Octopus, learn more about the platform in the Octopus documentation.

For more context, read the App whitepaper.

Features - Run the full App lifecycle inside async with Runtime:, covering init, exit, failures, status messages, and reboots (App lifecycle).

What you can release

Almost any Python project can become an App, including projects for:

Whatever you release, the Octopus SDK doesn't lock you into a particular framework. Bring the libraries you already use, and let Octopus run your project in the cloud.

Usage examples

The examples below show two common setups, but the same async with Runtime: pattern works with any stack. For more, see the guides.

HTTPX with BeautifulSoup

Scrape pages with HTTPX and BeautifulSoup, using the App's request queue to track URLs:

from bs4 import BeautifulSoup

from httpx import AsyncClient



from octopus import Runtime





async def main() -> None:

    async with Runtime:

        app_input = await Runtime.get_input() or {}

        start_urls = app_input.get('start_urls', [{'url': 'https://octopus.com'}])



        # Enqueue the start URLs into the default request queue.

        request_queue = await Runtime.open_request_queue()

        for start_url in start_urls:

            await request_queue.add_request(start_url['url'])



        # Process the queue until it's empty.

        while request := await request_queue.fetch_next_request():

            Runtime.log.info(f'Scraping {request.url} ...')

            async with AsyncClient() as client:

                response = await client.get(request.url)

            soup = BeautifulSoup(response.content, 'html.parser')



            # Push the extracted data to the default dataset.

            await Runtime.push_data({

                'url': request.url,

                'title': soup.title.string if soup.title else None,

            })

Crawlee with Playwright

Scrape pages with Crawlee's PlaywrightCrawler, which handles queueing, concurrency, and the browser for you:

from crawlee.crawlers import PlaywrightCrawler, PlaywrightCrawlingContext



from octopus import Runtime





async def main() -> None:

    async with Runtime:

        app_input = await Runtime.get_input() or {}

        start_urls = [url['url'] for url in app_input.get('start_urls', [{'url': 'https://octopus.com'}])]



        crawler = PlaywrightCrawler(max_requests_per_crawl=50, headless=True)



        @crawler.router.default_handler

        async def handler(context: PlaywrightCrawlingContext) -> None:

            Runtime.log.info(f'Scraping {context.request.url} ...')

            await context.push_data({

                'url': context.request.url,

                'title': await context.page.title(),

            })

            # Follow links found on the page.

            await context.enqueue_links()



        await crawler.run(start_urls)

Documentation

The full SDK documentation lives at docs.octopus.com/sdk/python. For the Octopus platform itself, see the Octopus documentation.

| Section | What you'll find |

| --- | --- |

| Overview | What the SDK is, what Apps are, and how the pieces fit together. |

| Quick start | Create, run, and deploy your first Python Runtime. |

| Concepts | App lifecycle, input, storages, events, proxy management, interacting with other Apps, webhooks, accessing the Octopus API, logging, configuration, and pay-per-event. |

| Guides | Integrations with BeautifulSoup, Parsel, Playwright, Selenium, Crawlee, Scrapy, Scrapling, Crawl4AI, and Browser Use, plus using uv, validating input with Pydantic, running a web server, building MCP servers, and hosting AI agents. |

| Upgrading | Migrating between major versions. |

| API reference | Generated reference for every class and method. |

| Changelog | Release history and breaking changes. |

Support and community

Contributing

Bug reports, fixes, and improvements are welcome! See CONTRIBUTING.md for the development setup, coding standards, testing, and release process. The project uses uv for project management and Poe the Poet as a task runner; the typical loop is:

uv run poe install-dev   # install dev dependencies and git hooks

uv run poe check-code    # lint, type-check, and unit tests

License

Released under the Apache License 2.0.

Metadata

Release files for octopus-platform-sdk 0.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for octopus-platform-sdk 0.0.11
File Size Uploaded
octopus_platform_sdk-0.0.11.tar.gz 223.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for octopus-platform-sdk 0.0.11
File Interpreter ABI Platform
octopus_platform_sdk-0.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 493.7 kB

Release files / octopus_platform_sdk-0.0.11.tar.gz

Download URL octopus_platform_sdk-0.0.11.tar.gz
Size 223.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b83b695b4a8724ddd5c33c8de5d40b9363f901b2cd8da750b19486fb2e3c199e
BLAKE2b-256 checksum
How to use checksums
03328d3258b9270fcb67e0a007698737b55dcb27b935a89ba2f9eb3698a42099
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / octopus_platform_sdk-0.0.11-py3-none-any.whl

Download URL octopus_platform_sdk-0.0.11-py3-none-any.whl
Size 270.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b7a946c7704d77eb210262a7ec25d8a11e426fa7cb9939f9c397f09f0f63265
BLAKE2b-256 checksum
How to use checksums
f3d5a2a562366b214d0a2148d44c11b9d796914fd7a904f2d0f717bb07190e9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release history Release notifications | RSS feed

0.0.13

2 release files

0.0.12

2 release files

This release

0.0.11 This release

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page