{"id":7890,"library":"zyte-api","title":"Zyte API Python Client","description":"The `zyte-api` Python client provides an asynchronous interface to the Zyte API, enabling programmatic access to web scraping functionalities such as smart browser rendering, automatic content extraction, and HTTP requests. It handles API communication, retries, and result parsing. Currently at version 0.9.0, it sees active development with frequent minor releases.","status":"active","version":"0.9.0","language":"en","source_language":"en","source_url":"https://github.com/zytedata/python-zyte-api","tags":["web scraping","api client","async","zyte api","rendering","headless browser"],"install":[{"cmd":"pip install zyte-api","lang":"bash","label":"Install `zyte-api`"}],"dependencies":[{"reason":"Provides asynchronous HTTP client capabilities for API communication.","package":"aiohttp"},{"reason":"Used for defining data classes for API request and response models.","package":"attrs"}],"imports":[{"symbol":"ZyteAPI","correct":"from zyte_api.zyte_api import ZyteAPI"},{"symbol":"ZyteAPIError","correct":"from zyte_api.errors import ZyteAPIError"}],"quickstart":{"code":"import os\nimport asyncio\nfrom zyte_api.zyte_api import ZyteAPI\n\napi_key = os.environ.get('ZYTE_API_KEY', '') # Set ZYTE_API_KEY environment variable or replace with your key\n\nasync def main():\n    if not api_key:\n        print(\"ZYTE_API_KEY environment variable not set. Skipping quickstart example.\")\n        return\n\n    api = ZyteAPI(api_key=api_key)\n    try:\n        print(\"Making a request to Zyte API for www.zyte.com...\")\n        result = await api.request_render(\n            url=\"https://www.zyte.com/\",\n            browserHtml=True,\n            screenshot=True,\n            httpResponseBody=True,\n            javascript=True\n        )\n\n        print(f\"Request Status: {result.status}\")\n        if result.browserData:\n            print(f\"Page title: {result.browserData.title}\")\n        if result.browserHtml:\n            print(f\"HTML (first 100 chars): {result.browserHtml[:100]}...\")\n        if result.screenshot:\n            print(f\"Screenshot (base64, first 50 chars): {result.screenshot[:50]}...\")\n        print(\"Successfully received Zyte API response.\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n\nif __name__ == '__main__':\n    asyncio.run(main())","lang":"python","description":"This quickstart demonstrates how to initialize the `ZyteAPI` client with an API key (preferably from an environment variable) and make an asynchronous `request_render` call to fetch HTML, a screenshot, and page data for a given URL. It uses `asyncio.run()` to execute the asynchronous operation."},"warnings":[{"fix":"Update your code to use attribute access for `RequestResult` objects, e.g., `result.field_name`.","message":"Starting from version 0.6.0, `ZyteAPI` methods (e.g., `request_render`) return a `RequestResult` object instead of a dictionary. Access data using dot notation (e.g., `result.browserData.title`) instead of dictionary-like square brackets (`result['browserData']['title']`).","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Wrap your API calls in an `async` function and use `await` for each call. Execute the main `async` function using `asyncio.run()`.","message":"The `ZyteAPI` client is primarily asynchronous. All API request methods (e.g., `request_render`) are coroutines and must be `await`ed within an `async` function. Running directly without `await` will result in `RuntimeWarning: coroutine was never awaited`.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure `os.environ['ZYTE_API_KEY']` is set with your valid Zyte API key, or instantiate the client as `api = ZyteAPI(api_key='YOUR_KEY')`.","message":"The Zyte API key is mandatory for authentication. It must be provided either via the `ZYTE_API_KEY` environment variable or passed directly to the `ZyteAPI` constructor as the `api_key` argument. Failure to do so will result in authentication errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade your Python environment to 3.8 or newer, or specify `zyte-api<0.7.0` in your `requirements.txt`.","message":"Support for Python 3.7 was dropped in version 0.7.0. If you are using Python 3.7, you must either upgrade your Python version to 3.8 or higher, or pin your `zyte-api` dependency to a version less than 0.7.0 (e.g., `zyte-api<0.7.0`).","severity":"breaking","affected_versions":">=0.7.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure that `api.request_render(...)` is preceded by `await` and executed inside an `async` function, which is then run using `asyncio.run()` or similar.","cause":"An asynchronous method of `ZyteAPI` was called without being `await`ed within an `async` context.","error":"RuntimeWarning: coroutine 'request_render' was never awaited"},{"fix":"Verify that your `ZYTE_API_KEY` environment variable is correctly set or that the `api_key` argument passed to `ZyteAPI` is valid and active.","cause":"The Zyte API key provided is either missing, incorrect, or does not have the necessary permissions for the requested operation.","error":"zyte_api.errors.ZyteAPIError: Authentication failed: Invalid API key or insufficient permissions."},{"fix":"Access the fields using dot notation instead, for example, `result.browserData.title` or `result.httpResponseBody`.","cause":"Attempting to access fields of the `RequestResult` object (returned by `ZyteAPI` methods since v0.6.0) using dictionary-like square bracket notation (`result['key']`).","error":"TypeError: 'RequestResult' object is not subscriptable"}]}