Skip to main content

Actor configuration

The Actor class gets configured using the Configuration class, which initializes itself based on the provided environment variables.

If you're using the Apify SDK in your Actors on the Apify platform, or Actors running locally through the Apify CLI, you don't need to configure the Actor class manually,unless you have some specific requirements, everything will get configured automatically.

If you need some special configuration, you can adjust it either through the Configuration class directly,or by setting environment variables when running the Actor locally.

To see the full list of configuration options, check the Configuration class or the list of environment variables that the Actor understands.

Configuring from code

This will cause the Actor to persist its state every 10 seconds:

from datetime import timedelta

from apify import Actor, Configuration, Event


async def main() -> None:
global_config = Configuration.get_global_configuration()
global_config.persist_state_interval = timedelta(seconds=10)

async with Actor:
# Define a handler that will be called for every persist state event.
async def save_state() -> None:
await Actor.set_value('STATE', 'Hello, world!')

# The save_state handler will be called every 10 seconds now.
Actor.on(Event.PERSIST_STATE, save_state)

Configuring via environment variables

All the configuration options can be set via environment variables. The environment variables are prefixed with APIFY_, and the configuration options are in uppercase, with underscores as separators. See the Configuration API reference for the full list of configuration options.

This Actor run will not persist its local storages to the filesystem:

APIFY_PERSIST_STORAGE=0 apify run