Skip to main content
Version: 3.4

Accessing Apify API

The Apify SDK provides a built-in instance of the Apify API Client for accessing Apify platform features beyond what the SDK covers directly.

The SDK wraps the most common operations (opening storages, reading input, charging, and starting other Actors) in high-level methods. To do things that it doesn't expose directly, such as managing schedules, listing your Actors and runs, working with builds or webhook dispatches, or reading another run's dataset, you can reach the full Apify API through the client. It provides a dedicated sub-client for each API resource (for example dataset, run, or schedule), and each operation returns plain Python data structures.

Actor client

To access the provided instance of ApifyClientAsync, you can use the Actor.apify_client property. This instance is already authenticated with the Actor's API token and points at the same API the Actor runs against.

For example, to get the details of your user, you can use this snippet:

Run on
import asyncio

from apify import Actor


async def main() -> None:
async with Actor:
# Create a new user client.
user_client = Actor.apify_client.user('me')

# Get information about the current user.
me = await user_client.get()
Actor.log.info(f'User: {me}')


if __name__ == '__main__':
asyncio.run(main())

You select a resource with the matching method (for example, Actor.apify_client.dataset('<dataset_id>') for a dataset or Actor.apify_client.run('<run_id>') for an Actor run), and then call the operation you need on the returned sub-client.

Actor new client

To create a completely new instance of the client (for example, to use a different user's token or change the client configuration), use the Actor.new_client method. It accepts an optional token and api_url, along with retry and timeout settings (max_retries, min_delay_between_retries, timeout), and returns a fresh ApifyClientAsync:

Run on
import asyncio

from apify import Actor

TOKEN = 'ANOTHER_USERS_TOKEN'


async def main() -> None:
async with Actor:
# Create a new user client with a custom token.
apify_client = Actor.new_client(token=TOKEN, max_retries=2)
user_client = apify_client.user('me')

# Get information about the another user.
them = await user_client.get()
Actor.log.info(f'Another user: {them}')


if __name__ == '__main__':
asyncio.run(main())

This is useful when the Actor's own token is not the right one, for instance when acting on behalf of another user, or when you want different retry and timeout behavior than the shared Actor.apify_client instance.

Conclusion

This page has shown how to reach the Apify API directly for platform features the SDK does not wrap. You can use the built-in client exposed by Actor.apify_client, or a freshly configured one created with Actor.new_client.

For the full API client documentation, see the Apify API Client for Python.