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

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