### Verify Python and Pip Installation Source: https://docs.apify.com/api/client/python/docs/overview/setting-up Commands to check if Python and Pip are installed on your system. These are prerequisites for installing the Apify client library. ```bash python --version ``` ```bash pip --version ``` -------------------------------- ### Verify Apify Client Installation Source: https://docs.apify.com/api/client/python/docs/overview/setting-up Checks if the 'apify-client' library is installed correctly by printing its version. This command-line execution confirms the installation. ```python python -c 'import apify_client; print(apify_client.__version__)' ``` -------------------------------- ### Start Actor and Fetch Dataset (Sync Python) Source: https://docs.apify.com/api/client/python/docs/overview/introduction Demonstrates how to use the synchronous Apify client to start an Actor, wait for its completion, and then fetch items from its default dataset. Requires the 'apify_client' library. It takes an API token and actor ID as input and outputs the dataset items. ```python from apify_client import ApifyClient # You can find your API token at https://console.apify.com/settings/integrations. TOKEN = 'MY-APIFY-TOKEN' def main() -> None: apify_client = ApifyClient(TOKEN) # Start an Actor and wait for it to finish. actor_client = apify_client.actor('john-doe/my-cool-actor') call_result = actor_client.call() if call_result is None: print('Actor run failed.') return # Fetch results from the Actor run's default dataset. dataset_client = apify_client.dataset(call_result['defaultDatasetId']) list_items_result = dataset_client.list_items() print(f'Dataset: {list_items_result}') ``` -------------------------------- ### Install Apify Client for Python Source: https://docs.apify.com/api/client/python/docs/overview/setting-up Installs the 'apify-client' package using Pip. This is the primary step to make the Apify API accessible from your Python environment. ```bash pip install apify-client ``` -------------------------------- ### Start Actor and Fetch Dataset (Async Python) Source: https://docs.apify.com/api/client/python/docs/overview/introduction Demonstrates how to use the asynchronous Apify client to start an Actor, wait for its completion, and then fetch items from its default dataset. Requires the 'apify_client' library. It takes an API token and actor ID as input and outputs the dataset items. ```python from apify_client import ApifyClientAsync # You can find your API token at https://console.apify.com/settings/integrations. TOKEN = 'MY-APIFY-TOKEN' async def main() -> None: apify_client = ApifyClientAsync(TOKEN) # Start an Actor and wait for it to finish. actor_client = apify_client.actor('john-doe/my-cool-actor') call_result = await actor_client.call() if call_result is None: print('Actor run failed.') return # Fetch results from the Actor run's default dataset. dataset_client = apify_client.dataset(call_result['defaultDatasetId']) list_items_result = await dataset_client.list_items() print(f'Dataset: {list_items_result}') ``` -------------------------------- ### Initialize Apify Client (Sync) Source: https://docs.apify.com/api/client/python/docs/overview/setting-up Initializes the synchronous Apify client using an API token. This setup is required for making standard, blocking API calls to the Apify platform. ```python from apify_client import ApifyClient TOKEN = 'MY-APIFY-TOKEN' def main() -> None: # Client initialization with the API token. apify_client = ApifyClient(TOKEN) ``` -------------------------------- ### Initialize Apify Client (Async) Source: https://docs.apify.com/api/client/python/docs/overview/setting-up Initializes the asynchronous Apify client using an API token. This setup is necessary for making asynchronous API calls to the Apify platform. ```python from apify_client import ApifyClientAsync TOKEN = 'MY-APIFY-TOKEN' async def main() -> None: # Client initialization with the API token. apify_client = ApifyClientAsync(TOKEN) ``` -------------------------------- ### Provide Input to Actor Run (Sync Python) Source: https://docs.apify.com/api/client/python/docs/overview/getting-started Shows how to pass input data to an Actor when starting its run using the synchronous Apify Client. Requires an API token and Actor ID. The input is provided as a JSON object. ```python from apify_client import ApifyClient TOKEN = 'MY-APIFY-TOKEN' def main() -> None: apify_client = ApifyClient(TOKEN) actor_client = apify_client.actor('username/actor-name') # Define the input for the Actor. run_input = { 'some': 'input', } # Start an Actor and waits for it to finish. call_result = actor_client.call(run_input=run_input) ``` -------------------------------- ### Provide Input to Actor Run (Async Python) Source: https://docs.apify.com/api/client/python/docs/overview/getting-started Shows how to pass input data to an Actor when starting its run using the asynchronous Apify Client. Requires an API token and Actor ID. The input is provided as a JSON object. ```python from apify_client import ApifyClientAsync TOKEN = 'MY-APIFY-TOKEN' async def main() -> None: apify_client = ApifyClientAsync(TOKEN) actor_client = apify_client.actor('username/actor-name') # Define the input for the Actor. run_input = { 'some': 'input', } # Start an Actor and waits for it to finish. call_result = await actor_client.call(run_input=run_input) ``` -------------------------------- ### Run Actor and Get Dataset Items (Sync Python) Source: https://docs.apify.com/api/client/python/docs/overview/getting-started Demonstrates how to use the synchronous Apify Client to run an Actor and retrieve items from its default dataset. Requires an API token and Actor ID. Outputs dataset items or a failure message. ```python from apify_client import ApifyClient # You can find your API token at https://console.apify.com/settings/integrations. TOKEN = 'MY-APIFY-TOKEN' def main() -> None: apify_client = ApifyClient(TOKEN) # Start an Actor and wait for it to finish. actor_client = apify.actor('john-doe/my-cool-actor') call_result = actor_client.call() if call_result is None: print('Actor run failed.') return # Fetch results from the Actor run's default dataset. dataset_client = apify_client.dataset(call_result['defaultDatasetId']) list_items_result = dataset_client.list_items() print(f'Dataset: {list_items_result}') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.