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.6.tar.gz (216.1 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.6-py3-none-any.whl (262.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for octopus_platform_sdk-0.0.6.tar.gz
Algorithm Hash digest
SHA256 1ff807be4869acd0ed3b7477f0aa98c9ccf1ce5a3a0b2de6d8ef6377d7dc6cfa
MD5 f63bb152c217f137f3a160fa764faa2a
BLAKE2b-256 d0929494cfcb7e2aefa2c9cc363fc6f6079edf167120fb7fd562e624d12a4bfd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for octopus_platform_sdk-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a97b569b984a74f12a14b116e16f92f0619f621997fbb9098716e94c54901098
MD5 81380360c8bfe618549c631a3c9e2bbd
BLAKE2b-256 74381b2a0f5e373ba054c125f111211fab1ef80b6100e6ffda776d661aa8ec5a

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

This release

0.0.6 This release

2 files

0.0.5

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