Skip to main content

A Python client library for the CodeAira API

Project description

CodeAira Python Client

PyPI version Python Version License

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: ConfigurationError if 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 in src/codeaira/models.py.
    • prompt (str): The prompt to send to the model.
    • context (str, optional): Additional context for the completion. Defaults to None.
    • app_id (str, optional): An identifier for your application. Defaults to None.
    • response_only (bool): If True (default), returns a DataOnlyResponse object containing just the completion text. If False, returns a FullCompletionResponse object with all details from the API response.
  • Returns: DataOnlyResponse or FullCompletionResponse depending on the response_only flag.

  • 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 the data (the completion string).
  • FullCompletionResponse: The complete response model, including success, data, log_id, thread_id, location, and error.

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). Contains status_code and error_message attributes.
  • NetworkError: For network-related problems during the request.
  • ValidationError: For Pydantic validation errors on request or response data.

Development

To set up for development:

  1. Clone the repository.
  2. Create and activate a virtual environment.
  3. Install the package in editable mode with development dependencies:
    pip install -e ".[dev]"
    
  4. Create a .env file with your credentials for running tests and examples.

License

This project is licensed under the terms of the LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codeaira_python-0.5.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codeaira_python-0.5.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

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

Hashes for codeaira_python-0.5.0.tar.gz
Algorithm Hash digest
SHA256 e6e4d9af307fdd0abecfaf26169781de669ec1eac0e1c8d77923e7f28a203a87
MD5 764af293ef64fc9d0617e3e25f331258
BLAKE2b-256 40202c9ad0c8420110d9dd6e87e0ac1de9c81d5ee5daac5f812ee8d38803f554

See more details on using hashes here.

File details

Details for the file codeaira_python-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for codeaira_python-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5540693c80773a833a00b98414caaeea81ba55111460b63fa2fe2c50e175502f
MD5 99abcc646c0b8eb7d6e0213d790727c1
BLAKE2b-256 0b1e2ed86d685605fc514a47e6278882aa708807005e94e565f5d66e00ca28f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page