A Python client library for the CodeAira API
Project description
CodeAira Python Client
A Python client library for the CodeAira API.
Installation
You can install codeaira-python from PyPI:
pip install codeaira-python
Configuration
The client requires your CodeAira API key and the API base URL. It loads these from environment variables. You can either export them in your shell or create a .env file in your project's root directory.
Example .env file:
CODEAIRA_API_KEY="your_api_key_here"
CODEAIRA_BASE_URL="codeaira-api-base-url here"
If these variables are not found, a ConfigurationError will be raised.
Usage
Here is a basic example of how to use the CodeAiraClient to get a text completion.
from codeaira import CodeAiraClient, DataOnlyResponse, FullCompletionResponse
from codeaira.exceptions import CodeAiraException
# The client automatically loads configuration from environment variables
# or a .env file.
client = CodeAiraClient()
try:
# Example 1: Get only the completion data (default behavior)
response: DataOnlyResponse = client.complete_text(
model_name="gemini-2.5-flash",
prompt="Write a short story about a robot who discovers music."
)
print("Completion Data Only:")
print(response.data)
print("-" * 20)
# Example 2: Get the full API response object
full_response: FullCompletionResponse = client.complete_text(
model_name="gemini-2.5-flash",
prompt="Translate 'hello world' to French.",
response_only=False
)
print("Full API Response:")
# .model_dump_json() is a pydantic method
print(full_response.model_dump_json(indent=2))
except CodeAiraException as e:
print(f"An error occurred: {e}")
API Reference
CodeAiraClient
The main client for interacting with the CodeAira API.
__init__()
Initializes the client. It reads CODEAIRA_API_KEY and CODEAIRA_BASE_URL from the environment.
- Raises:
ConfigurationErrorif the required environment variables are not set.
complete_text(model_name, prompt, context=None, app_id=None, response_only=True)
Sends a completion request to the CodeAira API.
-
Parameters:
model_name(str): The name of the model to use for the completion. A list of valid models can be found insrc/codeaira/models.py.prompt(str): The prompt to send to the model.context(str, optional): Additional context for the completion. Defaults toNone.app_id(str, optional): An identifier for your application. Defaults toNone.response_only(bool): IfTrue(default), returns aDataOnlyResponseobject containing just the completion text. IfFalse, returns aFullCompletionResponseobject with all details from the API response.
-
Returns:
DataOnlyResponseorFullCompletionResponsedepending on theresponse_onlyflag. -
Raises:
ValidationError: If the request data fails Pydantic validation.NetworkError: For network-related issues (e.g., connection problems).APIError: If the CodeAira API returns an error response.
Models
The library uses Pydantic models for data validation and serialization.
CodeAiraRequest: The model for the request sent to the API.DataOnlyResponse: A simplified response model containing only thedata(the completion string).FullCompletionResponse: The complete response model, includingsuccess,data,log_id,thread_id,location, anderror.
Exceptions
Custom exceptions are raised for specific error conditions.
CodeAiraException: The base exception for all library-specific errors.ConfigurationError: For issues with configuration, like a missing API key.APIError: When the API returns an error (e.g., status code 4xx or 5xx). Containsstatus_codeanderror_messageattributes.NetworkError: For network-related problems during the request.ValidationError: For Pydantic validation errors on request or response data.
Development
To set up for development:
- Clone the repository.
- Create and activate a virtual environment.
- Install the package in editable mode with development dependencies:
pip install -e ".[dev]"
- Create a
.envfile with your credentials for running tests and examples.
License
This project is licensed under the terms of the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codeaira_python-0.5.0.tar.gz.
File metadata
- Download URL: codeaira_python-0.5.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6e4d9af307fdd0abecfaf26169781de669ec1eac0e1c8d77923e7f28a203a87
|
|
| MD5 |
764af293ef64fc9d0617e3e25f331258
|
|
| BLAKE2b-256 |
40202c9ad0c8420110d9dd6e87e0ac1de9c81d5ee5daac5f812ee8d38803f554
|
File details
Details for the file codeaira_python-0.5.0-py3-none-any.whl.
File metadata
- Download URL: codeaira_python-0.5.0-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5540693c80773a833a00b98414caaeea81ba55111460b63fa2fe2c50e175502f
|
|
| MD5 |
99abcc646c0b8eb7d6e0213d790727c1
|
|
| BLAKE2b-256 |
0b1e2ed86d685605fc514a47e6278882aa708807005e94e565f5d66e00ca28f6
|