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.
my_actor/main.py
pyproject.toml
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
11import sys12
13from apify import Actor14
15
16async def main() -> None:17 """Define a main entry point for the Apify Actor.18
19 This coroutine is executed using `asyncio.run()`, so it must remain an asynchronous function for proper execution.20 Asynchronous execution is required for communication with the Apify platform.21
22 This is a minimal, general-purpose Actor: it reads an input, does a little work with it, logs its progress, and23 stores a result in the dataset. Replace the body with whatever your Actor should do, for example a scraper, a24 browser automation, an AI agent, an MCP server, or a web server.25 """26 async with Actor:27 # uv manages both the dependencies and the Python version, so the interpreter running here is exactly the28 # one pinned in `.python-version`.29 python_version = '.'.join(map(str, sys.version_info[:3]))30 Actor.log.info(f'Hello from a uv-managed Apify Actor, running on Python {python_version}!')31
32 # Retrieve the Actor input. The structure of the input is defined in `input_schema.json`.33 actor_input = await Actor.get_input() or {}34 name = actor_input.get('name', 'world')35 repeat = actor_input.get('repeat', 3)36
37 # Do something with the input. Here we simply greet the given name a few times.38 for i in range(1, repeat + 1):39 Actor.log.info(f'[{i}/{repeat}] Hello, {name}!')40
41 # Save a structured result to the dataset, which is a table-like storage.42 await Actor.push_data(43 {44 'greeting': f'Hello, {name}!',45 'repeated': repeat,46 'python_version': python_version,47 'managed_by': 'uv',48 }49 )A general-purpose Actor template for Python, with the project and its dependencies managed by uv - a fast Python package and project manager. It's a minimal starting point for any kind of Actor, for example a scraper, a browser automation, an AI agent, an MCP server, a RAG pipeline, or a standby web server.
The example code reads an input, does a little work with it, logs its progress, and stores a result in a dataset . Replace the body of main() with whatever your Actor should do. The only thing this template locks in is the tooling, uv, not the use case.
- uv - a single fast tool that manages the project's Python version (
.python-version), virtual environment (.venv), and dependencies (pyproject.toml+uv.lock) - Reproducible builds - the
uv.locklockfile guarantees that the Actor's Docker image is built with exactly the dependency versions you developed against - Apify SDK for Python - a toolkit for building Apify Actors in Python
- Input schema - define and easily validate a schema for your Actor's input
- Dataset - store structured data where each object stored has the same attributes
Actor.get_input()reads the input defined in the input schema- The Actor logs the Python version it runs on (managed by uv) and greets the given name a few times
Actor.push_data(...)stores a structured result in the dataset
This is only a placeholder so the template runs out of the box. Swap it for your own logic and add the dependencies you need with uv add.
Install uv first, then use it for everyday project management:
# Install the dependencies into the .venv virtual environment. uv also downloads# the pinned Python version from .python-version if it's not installed yet.uv sync# Run the Actor locally (the Apify CLI automatically uses the .venv environment).apify run# Add or remove a dependency (updates pyproject.toml and uv.lock).uv add <package>uv remove <package># Upgrade all dependencies to the latest versions allowed by pyproject.toml.uv lock --upgrade && uv sync
The Actor's Dockerfile installs the dependencies with uv sync --locked --no-dev, so the image is built with exactly the versions recorded in uv.lock (skipping any development-only dependencies you add under [dependency-groups]). Commit uv.lock and .python-version whenever they change.
- Apify SDK for Python: uv guide
- uv: Official documentation
- Apify SDK for Python documentation
- Python tutorials in Academy
- Integration with Make, GitHub, Zapier, Google Drive, and other apps
- Video guide on getting data using the Apify API
- A short guide on how to build Actors using code templates:
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 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.
Python Selenium scraper
A Chrome browser scraper that renders JavaScript before extracting data. Good for social feeds, dashboards, or single-page apps.