-
Notifications
You must be signed in to change notification settings - Fork 14
docs: Refactor documentation structure and add new content #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
| id: overview | ||
| title: Overview | ||
| description: 'The official Python library for accessing the Apify API, providing synchronous and asynchronous interfaces for Actors, datasets, and storage.' | ||
| --- | ||
|
|
||
| ## Introduction | ||
|
|
||
| The [Apify client for Python](https://github.com/apify/apify-client-python) is the official library to access the [Apify REST API](/api/v2) from your Python applications. It provides useful features like automatic retries and convenience functions that improve the experience of using the Apify API. | ||
|
|
||
| Key features: | ||
|
|
||
| - Synchronous and asynchronous interfaces for flexible integration | ||
| - Automatic retries for improved reliability | ||
| - JSON encoding with UTF-8 for all requests and responses | ||
| - Comprehensive API coverage for [Actors](/platform/actors), [datasets](/platform/storage/dataset), [key-value stores](/platform/storage/key-value-store), and more | ||
|
|
||
| ## Next steps | ||
|
|
||
| Now that you're familiar with the basics, explore more advanced features: | ||
|
|
||
| - [Asyncio support](/concepts/asyncio-support) - Learn about asynchronous programming with the client | ||
| - Common use-case examples like: | ||
| - [Passing an input to Actor](/api/client/python/docs/examples/passing-input-to-actor) | ||
| - [Retrieve Actor data](/api/client/python/docs/examples/retrieve-actor-data) | ||
| - [API Reference](/api/client/python/reference) - Browse the complete API documentation |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| --- | ||
| id: installation | ||
| title: Installation | ||
| description: 'How to install the Apify client for Python and verify the installation.' | ||
| --- | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Before installing the Apify client, ensure your system meets the following requirements: | ||
|
|
||
| - _An Apify account_ | ||
| - _Python 3.10 or higher_: You can download Python from the [official website](https://www.python.org/downloads/). | ||
| - _Python package manager_: While this guide uses [pip](https://pip.pypa.io/en/stable/), you can also use any package manager you want. | ||
|
|
||
| To verify that Python and pip are installed, run the following commands: | ||
|
|
||
| ```sh | ||
| python --version | ||
| ``` | ||
|
|
||
| ```sh | ||
| pip --version | ||
| ``` | ||
|
|
||
| If these commands return the respective versions, you're ready to continue. | ||
|
|
||
| ## Installation | ||
|
|
||
| The Apify client is available as the [`apify-client`](https://pypi.org/project/apify-client/) package on PyPI. To install it, run: | ||
|
|
||
| ```sh | ||
| pip install apify-client | ||
| ``` | ||
|
|
||
| After installation, verify that the client is installed correctly by checking its version: | ||
|
|
||
| ```sh | ||
| python -c 'import apify_client; print(apify_client.__version__)' | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| 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') | ||
|
|
||
| # Start an Actor and waits for it to finish | ||
| finished_actor_run = await actor_client.call() | ||
|
|
||
| # Starts an Actor and waits maximum 60s (1 minute) for the finish | ||
| actor_run = await actor_client.start(wait_for_finish=60) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from apify_client import ApifyClient | ||
|
|
||
| TOKEN = 'MY-APIFY-TOKEN' | ||
|
|
||
|
|
||
| def main() -> None: | ||
| apify_client = ApifyClient(TOKEN) | ||
| actor_client = apify_client.actor('username/actor-name') | ||
|
|
||
| # Start an Actor and waits for it to finish | ||
| finished_actor_run = actor_client.call() | ||
|
|
||
| # Starts an Actor and waits maximum 60s (1 minute) for the finish | ||
| actor_run = actor_client.start(wait_for_finish=60) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| from apify_client import ApifyClientAsync | ||
|
|
||
| TOKEN = 'MY-APIFY-TOKEN' | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| apify_client = ApifyClientAsync(TOKEN) | ||
|
|
||
| # Initialize the dataset client | ||
| dataset_client = apify_client.dataset('dataset-id') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can have a module-level constant |
||
|
|
||
| # Define the pagination parameters | ||
| limit = 1000 # Number of items per page | ||
| offset = 0 # Starting offset | ||
| all_items = [] # List to store all fetched items | ||
|
|
||
| while True: | ||
| # Fetch a page of items | ||
| response = await dataset_client.list_items(limit=limit, offset=offset) | ||
| items = response.items | ||
| total = response.total | ||
|
|
||
| print(f'Fetched {len(items)} items') | ||
|
|
||
| # Add the fetched items to the complete list | ||
| all_items.extend(items) | ||
|
|
||
| # Exit the loop if there are no more items to fetch | ||
| if offset + limit >= total: | ||
| break | ||
|
|
||
| # Increment the offset for the next page | ||
| offset += limit | ||
|
|
||
| print(f'Overall fetched {len(all_items)} items') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| from apify_client import ApifyClient | ||
|
|
||
| TOKEN = 'MY-APIFY-TOKEN' | ||
|
|
||
|
|
||
| def main() -> None: | ||
| apify_client = ApifyClient(TOKEN) | ||
|
|
||
| # Initialize the dataset client | ||
| dataset_client = apify_client.dataset('dataset-id') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it would be more practical to retrieve the dataset client by dataset's name?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can have a module-level constant |
||
|
|
||
| # Define the pagination parameters | ||
| limit = 1000 # Number of items per page | ||
| offset = 0 # Starting offset | ||
| all_items = [] # List to store all fetched items | ||
|
|
||
| while True: | ||
| # Fetch a page of items | ||
| response = dataset_client.list_items(limit=limit, offset=offset) | ||
| items = response.items | ||
| total = response.total | ||
|
|
||
| print(f'Fetched {len(items)} items') | ||
|
|
||
| # Add the fetched items to the complete list | ||
| all_items.extend(items) | ||
|
|
||
| # Exit the loop if there are no more items to fetch | ||
| if offset + limit >= total: | ||
| break | ||
|
|
||
| # Increment the offset for the next page | ||
| offset += limit | ||
|
|
||
| print(f'Overall fetched {len(all_items)} items') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from apify_client import ApifyClientAsync | ||
|
|
||
| TOKEN = 'MY-APIFY-TOKEN' | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| apify_client = ApifyClientAsync(TOKEN) | ||
| run_client = apify_client.run('MY-RUN-ID') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can have a module-level constant |
||
| log_client = run_client.log() | ||
|
|
||
| async with log_client.stream() as log_stream: | ||
| if log_stream: | ||
| async for bytes_chunk in log_stream.aiter_bytes(): | ||
| print(bytes_chunk) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from apify_client import ApifyClient | ||
|
|
||
| TOKEN = 'MY-APIFY-TOKEN' | ||
|
|
||
|
|
||
| def main() -> None: | ||
| apify_client = ApifyClient(TOKEN) | ||
| run_client = apify_client.run('MY-RUN-ID') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can have a module-level constant |
||
| log_client = run_client.log() | ||
|
|
||
| with log_client.stream() as log_stream: | ||
| if log_stream: | ||
| for bytes_chunk in log_stream.iter_bytes(): | ||
| print(bytes_chunk) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be more practical to retrieve the dataset client by dataset's name?