Skip to main content
Version: Next

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.

Actor client

To access the provided instance of ApifyClientAsync, you can use the Actor.apify_client property.

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())

Actor new client

If you want to create a completely new instance of the client, for example, to get a client for a different user or change the configuration of the client, you can use the Actor.new_client method:

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())

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