Skip to main content

Actor configuration and environment variables

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 apify import Actor
from apify.consts import ActorEventTypes

async def main():
global_config = Configuration.get_global_configuration()
global_config.persist_state_interval_millis = 10000

async with Actor:
async def save_state():
await Actor.set_value('STATE', 'Hello, world!')

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

Configuring via environment variables

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