Skip to main content

Python client for the Condensation.ai API

Project description

Condy: Python Client for Condensation.ai

A modern, async Python client library for interacting with the Condensation.ai API, providing seamless access to document processing and RAG (Retrieval-Augmented Generation) capabilities.

Features

  • 🚀 Fully async implementation using httpx
  • 📄 Document processing and chunking
  • 🔍 RAG (Retrieval-Augmented Generation) querying
  • 💪 Type hints and modern Python practices
  • ⚡ Efficient markdown processing and page management
  • 🛡️ Comprehensive error handling
  • 📝 Rich document metadata support

Installation

pip install condy

Quick Start

import asyncio
from condy import CondyClient

async def main():
    # Initialize the client
    client = CondyClient(api_key="your-api-key")
    
    # Process a document from URL with metadata
    doc_output = await client.process_document(
        url="https://example.com/document.md",
        filename="document.md",
        file_key="custom-key",
        public_url="https://example.com/document.md"
    )
    
    # Query the document using RAG
    response = await client.query_rag(
        question="What are the key points?",
        document_id=doc_output.document_id
    )
    
    print(response.answer)

asyncio.run(main())

Core Features

Document Processing

# Upload pages directly with metadata
pages = {
    1: "Page 1 content",
    2: "Page 2 content"
}
doc_output = await client.upload_pages(
    pages=pages,
    filename="document.txt",
    file_key="unique-identifier",
    public_url="https://example.com/document.txt"
)

# Or process markdown from URL with metadata
doc_output = await client.process_document(
    url="https://example.com/document.md",
    filename="document.md",
    file_key="doc-123",
    public_url="https://example.com/document.md"
)

RAG Queries

# Query a document
response = await client.query_rag(
    question="What does the document say about X?",
    document_id="doc-id",
    max_chunks=5
)

# Access the response
print(response.answer)
print(response.source_pages)  # List of source pages used

Chunk Management

# Fetch document chunks
chunks = await client.fetch_chunks(
    document_id="doc-id",
    include_embeddings=False  # Set to True to include vector embeddings
)

Configuration

The client can be configured with custom settings:

client = CondyClient(
    api_key="your-api-key",
    base_url="https://custom-url.example.com",  # Optional
    timeout=60.0  # Custom timeout in seconds
)

Document Metadata

The library supports rich document metadata:

# Process document with full metadata
doc_output = await client.process_document(
    url="https://example.com/doc.pdf",
    content_type="pdf",
    filename="important-doc.pdf",  # Optional: Custom filename
    file_key="doc-2023-01",       # Optional: Unique identifier
    public_url="https://example.com/doc.pdf"  # Optional: Public access URL
)

Error Handling

The library provides specific exceptions for different error cases:

  • NetworkError: For connection and network-related issues
  • TimeoutError: For request timeout issues
  • APIError: For API-specific errors with status codes and details
from condy import NetworkError, TimeoutError, APIError

try:
    response = await client.query_rag(question="...", document_id="...")
except TimeoutError:
    print("Request timed out")
except NetworkError:
    print("Network error occurred")
except APIError as e:
    print(f"API error: {e.status_code} - {e.detail}")

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

The usage of the library is subject to the Condensation.ai Terms of Service.

Support

For support, please contact support@condensation.ai.

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

condy-0.3.2.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

condy-0.3.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file condy-0.3.2.tar.gz.

File metadata

  • Download URL: condy-0.3.2.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.6

File hashes

Hashes for condy-0.3.2.tar.gz
Algorithm Hash digest
SHA256 6ca013d99fc198ed91e0f8a8e873d5d672b42c77724a88171ede8310e66e75bf
MD5 76ffb7609e79d7ec7b52066ac09c9f8e
BLAKE2b-256 0799e3d4acacf781036682d270e6f6896fd5e321c45fa850bd6ea326c63cceee

See more details on using hashes here.

File details

Details for the file condy-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: condy-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.6

File hashes

Hashes for condy-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e316d3e1476dca35ba90d5c315b07305f8574f755884215e7b3717f055b0f5c3
MD5 1778f470a80d25901c32509ebba6d33b
BLAKE2b-256 4acc5524dca0b5b0706b6c5dcfd06b93dd2de341f0956c6347b77b18e17282bf

See more details on using hashes here.

Supported by

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