Python API Actor
An Actor that stays running, ready to respond to HTTP requests. Good for APIs and real-time services.
my_actor/main.py
my_actor/__main__.py
1"""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/python7"""8
9from __future__ import annotations10
11from http.server import HTTPServer, SimpleHTTPRequestHandler12
13from apify import Actor14
15
16class GetHandler(SimpleHTTPRequestHandler):17 """A simple GET HTTP handler that will respond with a message."""18
19 def do_GET(self) -> None:20 """Handle GET request and respond with a message."""21 # Handle Apify standby readiness probe22 # https://docs.apify.com/platform/actors/development/programming-interface/standby#readiness-probe23 if 'x-apify-container-server-readiness-probe' in self.headers:24 self.send_response(200)25 self.end_headers()26 self.wfile.write(b'ok')27 return28
29 self.send_response(200)30 self.end_headers()31 self.wfile.write(b'Hello from Actor Standby!')32
33
34async def main() -> None:35 """Define a main entry point for the Apify Actor.36
37 This coroutine is executed using `asyncio.run()`, so it must remain an asynchronous function for proper execution.38 Asynchronous execution is required for communication with Apify platform, and it also enhances performance in39 the field of web scraping significantly.40 """41 async with Actor:42 # A simple HTTP server listening on the Actor web server port.43 with HTTPServer(('', Actor.configuration.web_server_port), GetHandler) as http_server:44 http_server.serve_forever()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.
BeautifulSoup crawler
Get data from every page on a site. Good for simple sites like blogs, news, or product listings, but it can't run client-side JavaScript. Uses BeautifulSoup, Python's most popular HTML parser.
Empty Python Actor
An Actor with the Apify SDK set up, so you can build any tool you need.
Python one-page scraper
Get data from one web page with BeautifulSoup. The simplest way to start scraping.
Python project managed by uv
A general-purpose Python Actor with its project and dependencies managed by the uv package manager. A minimal starting point for any use case.
Python multi-page scraper
Get data from multiple web pages with BeautifulSoup. Fast and light for simple sites.
Python Playwright scraper
A real-browser scraper that gets data HTTP scrapers miss. Good for social feeds, dashboards, or single-page apps.