API Key Configuration
The Reducto Python SDK requires an API key to authenticate requests to the Reducto API. You can provide your API key when initializing the client.
Basic Usage
import os
from reducto import Reducto
client = Reducto(
api_key=os.environ.get("REDUCTO_API_KEY"), # This is the default and can be omitted
)
Using Environment Variables
The SDK automatically reads the REDUCTO_API_KEY environment variable by default. If this variable is set, you can omit the api_key parameter:
from reducto import Reducto
client = Reducto() # Automatically uses REDUCTO_API_KEY from environment
The api_key parameter defaults to os.environ.get("REDUCTO_API_KEY") and can be omitted if the environment variable is set.
Using python-dotenv
For better security and to keep your API key out of source control, we recommend using python-dotenv to manage your environment variables.
Install python-dotenv
pip install python-dotenv
Create a .env file
Create a .env file in your project root:REDUCTO_API_KEY="your-api-key-here"
Load environment variables
Load the environment variables in your Python code:from dotenv import load_dotenv
from reducto import Reducto
load_dotenv() # Load variables from .env file
client = Reducto() # API key is loaded from environment
Add .env to .gitignore
Ensure your .env file is added to .gitignore to prevent committing sensitive data:echo ".env" >> .gitignore
Never commit your API key to source control. Always use environment variables or a .env file that is excluded from version control.
Async Client Authentication
The async client uses the same authentication configuration:
import os
from reducto import AsyncReducto
client = AsyncReducto(
api_key=os.environ.get("REDUCTO_API_KEY"),
)