Aiven Client Library

raw JSON →
4.13.0 verified Thu Apr 16 auth: no python

The aiven-client library provides both a command-line client (`avn`) and a Python API for interacting with Aiven.io services. It's actively maintained with frequent minor releases, currently at version 4.13.0, introducing new features and deprecating older ones regularly.

pip install aiven-client
error ModuleNotFoundError: No module named 'aiven'
cause The `aiven-client` library is not installed or the Python environment is incorrect.
fix
Install the library using pip install aiven-client. Ensure you are running your script with the Python interpreter where the library was installed.
error aiven.client.client.AivenError: Authentication required
cause The AivenClient was initialized without a valid API token, or the provided token is expired/incorrect.
fix
Set the AIVEN_TOKEN environment variable with your Aiven API token before running your script, or pass a valid auth_token directly to the AivenClient constructor.
error AttributeError: 'AivenClient' object has no attribute 'get_teams'
cause You are trying to call a method that was part of a deprecated feature (`teams`) and has been removed from the client library.
fix
Refer to the Aiven documentation for current methods of managing user access and permissions, which no longer involve 'teams' functionality programmatically in the client library.
breaking Python 3.9 support was dropped. Ensure your environment uses Python 3.10 or newer.
fix Upgrade your Python interpreter to 3.10 or later.
breaking The `teams` commands and related API methods have been removed.
fix Migrate to using application users and permissions for managing access, as `teams` functionality is no longer available. Refer to Aiven documentation for current access management practices.
breaking Python 3.8 support was dropped. Ensure your environment uses Python 3.9 or newer.
fix Upgrade your Python interpreter to 3.9 or later. For current versions, use 3.10+.
breaking Support for InfluxDB services was dropped.
fix If you relied on `aiven-client` for InfluxDB management, this functionality is no longer present. Consider alternative methods or Aiven Console for managing existing InfluxDB services.
breaking Aiven Redis services were replaced with Aiven Valkey services. While many operations remain similar, some Redis-specific commands or attributes may have changed.
fix Review your code for any Redis-specific API calls. Adapt to Valkey-compatible methods and terminology. Existing Redis services were automatically migrated to Valkey.
gotcha API token authentication is mandatory for programmatic access. Using an invalid or expired token will result in authentication errors.
fix Always provide a valid Aiven API token during client initialization. It's recommended to load this from environment variables (e.g., `AIVEN_TOKEN`) or a secure configuration system.

Initialize the AivenClient using an API token from an environment variable and list your Aiven projects.

import os
from aiven.client import AivenClient

aiven_api_token = os.environ.get("AIVEN_TOKEN", "")

if not aiven_api_token:
    print("Please set the AIVEN_TOKEN environment variable with your Aiven API token.")
else:
    try:
        client = AivenClient(auth_token=aiven_api_token)
        projects = client.get_projects()
        print(f"Successfully connected to Aiven. Found {len(projects)} projects:")
        for project in projects:
            print(f"  - {project['project_name']}")
    except Exception as e:
        print(f"Error connecting or listing projects: {e}")