Skip to main content

Introducing Client Initialization from Environment in Python SDKs

· 2 min read

We have added support for initializing the SDK directly from environment to simplify setup and enhance developer experience.

Details

APIMatic's Python SDK now supports initializing clients directly from environment variables, eliminating the need for hardcoded configuration values. This streamlines environment-specific deployments, enhances credential security, and allows runtime configuration changes without code modifications.

What's New?

We have introduced a from_environment() class method in the SDK client that builds the client using values defined in system environment variables or a .env file, with optional overrides via keyword arguments.

Initializing the Client from the Environment

from sdk_client import SdkClient

# Initialize using values from system environment or .env file
client = SdkClient.from_environment(dotenv_path='/path/to/.env')

Overrides take precedence:

from sdk_client import SdkClient

# Overrides the timeout defined in environment variables
client = SdkClient.from_environment(timeout=0)

Example .env File

PORT=443
ENVIRONMENT=production
TIMEOUT=60
MAX_RETRIES=3
BACKOFF_FACTOR=2
RETRY_STATUSES=408,413
RETRY_METHODS=GET,PUT,DELETE

# Proxy Configuration
PROXY_ADDRESS=http://localhost:3000
PROXY_PORT=8080
PROXY_USERNAME=username
PROXY_PASSWORD=password

Developer Portal Enhancements

A new Environment-Based Client Initialization section has been added to the SDK Infrastructure section. This section contains information on how to initialize the SDK client from environment and includes .env file examples for the SDK with all possible configurations.

Learn more about Client Initialization from Environment feature