Actor structure
All Python Actor templates follow the same structure.
The .actor
directory contains the Actor configuration,
such as the Actor's definition and input schema, and the Dockerfile necessary to run the Actor on the Apify platform.
The Actor's runtime dependencies are specified in the requirements.txt
file,
which follows the standard requirements file format.
The Actor's source code is in the src
folder. This folder contains two important files:
main.py
, which contains the main function of the Actor,
and __main__.py
, which is the entrypoint of the Actor package,
setting up the Actor logger
and executing the Actor's main function via asyncio.run()
.
- main.py
- __main.py__
from apify import Actor
async def main():
async with Actor:
Actor.log.info('Actor input:', await Actor.get_input())
await Actor.set_value('OUTPUT', 'Hello, world!')
import asyncio
import logging
from apify.log import ActorLogFormatter
from .main import main
asyncio.run(main())
If you want to modify the Actor structure,
you need to make sure that your Actor is executable as a module, via python -m src
,
as that is the command started by apify run
in the Apify CLI.
We recommend keeping the entrypoint for the Actor in the src/__main__.py
file.