Back to template gallery

Standby Python project

Template with basic structure for an Actor using Standby mode that allows you to easily add your own functionality.

Language

python

Use cases

Starter

src/main.py

src/__main__.py

1"""This module defines the main entry point for the Apify Actor.
2
3Feel free to modify this file to suit your specific needs.
4
5To build Apify Actors, utilize the Apify SDK toolkit, read more at the official documentation:
6https://docs.apify.com/sdk/python
7"""
8
9from http.server import HTTPServer, SimpleHTTPRequestHandler
10
11from apify import Actor
12
13
14class GetHandler(SimpleHTTPRequestHandler):
15    """A simple GET HTTP handler that will respond with a message."""
16
17    def do_GET(self) -> None:
18        self.send_response(200)
19        self.end_headers()
20        self.wfile.write(b'Hello from Actor Standby!')
21
22
23async def main() -> None:
24    """Main entry point for the Apify Actor.
25
26    This coroutine is executed using `asyncio.run()`, so it must remain an asynchronous function for proper execution.
27    Asynchronous execution is required for communication with Apify platform, and it also enhances performance in
28    the field of web scraping significantly.
29    """
30    async with Actor:
31        # A simple HTTP server listening on Actor standby port.
32        with HTTPServer(('', Actor.config.standby_port), GetHandler) as http_server:
33            http_server.serve_forever()

Python standby template

Start a new web scraping project quickly and easily in Python with our Standby project template. It provides a basic structure for the Actor with Apify SDK and allows you to easily add your own functionality.

Included features

  • Apify SDK for Python - a toolkit for building Apify Actors and scrapers in Python

Resources

Already have a solution in mind?

Sign up for a free Apify account and deploy your code to the platform in just a few minutes! If you want a head start without coding it yourself, browse our Store of existing solutions.