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. |

Related projects

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.

Download files

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

Source Distribution

octopus_platform_sdk-0.0.5.tar.gz (215.6 kB view details)

Uploaded Source

Built Distribution

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

octopus_platform_sdk-0.0.5-py3-none-any.whl (263.3 kB view details)

Uploaded Python 3

File details

Details for the file octopus_platform_sdk-0.0.5.tar.gz.

File metadata

  • Download URL: octopus_platform_sdk-0.0.5.tar.gz
  • Upload date:
  • Size: 215.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.9

File hashes

Hashes for octopus_platform_sdk-0.0.5.tar.gz
Algorithm Hash digest
SHA256 1ebe14bcb6471eb1de034dbf28a1d97d3b71d381421b03b3b17b27e38b769e7d
MD5 24182af8facb354584515ea817b25db5
BLAKE2b-256 a0658882ad5843bed9a5e399fff8085d165c99be146648fcc95163598cc04a96

See more details on using hashes here.

File details

Details for the file octopus_platform_sdk-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for octopus_platform_sdk-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 59aa5a9474c9a73e9a5292e551b4d5be3fb8a59ed7ede205e1bf72b3a1777f9a
MD5 59bfb10ffa4d9ba15a58d90dcde73f16
BLAKE2b-256 ad85cd8e3f55da8d4c121660f12ea8a8d35977099a7f7e38a7d7f2e11288b385

See more details on using hashes here.

Release history Release notifications | RSS feed

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

This release

0.0.5 This release

2 files

0.0.4

2 files

0.0.3

2 files

0.0.1

2 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