API key

After you sign up for a Zyte API account, copy your API key.

It is recommended to configure your API key through an environment variable, so that it can be picked by both the command-line client and the Python client library:

  • On Windows:

    > set ZYTE_API_KEY=YOUR_API_KEY
    
  • On macOS and Linux:

    $ export ZYTE_API_KEY=YOUR_API_KEY
    

Instead of exporting the variable yourself, you can store it in a .env file and let it be loaded automatically:

.env
ZYTE_API_KEY=YOUR_API_KEY

The nearest .env file is looked up in the current working directory and its parent directories. Only the ZYTE_API_KEY variable is read from it; any other variables are ignored, a ZYTE_API_KEY set in the environment takes precedence over the file, and your environment is never modified.

To read a .env file from a different location, use the --dotenv-path switch of the command-line client, or the dotenv_path parameter of the Python client classes:

zyte-api --dotenv-path /path/to/.env 
from zyte_api import ZyteAPI

client = ZyteAPI(dotenv_path="/path/to/.env")

Alternatively, you may pass your API key to the clients directly:

  • To pass your API key directly to the command-line client, use the --api-key switch:

    zyte-api --api-key YOUR_API_KEY 
  • To pass your API key directly to the Python client classes, use the api_key parameter when creating a client object:

    from zyte_api import ZyteAPI
    
    client = ZyteAPI(api_key="YOUR_API_KEY")
    
    from zyte_api import AsyncZyteAPI
    
    client = AsyncZyteAPI(api_key="YOUR_API_KEY")