The official Python SDK for the ColiVara API
Project description
colivara-py
The official Python SDK for the ColiVara API. ColiVara is a document search and retrieval API that uses advanced machine learning techniques to index and search documents. This SDK allows you to interact with the API to create collections, upload documents, search for documents, and generate embeddings.
Installation
Install colivara-py using pip:
pip install colivara-py
Usage
Refer to the ColiVara API documentation for detailed guidance on how to use this library.
Requirements
- You need access to the ColiVara API, which you can self-host (see ColiVara API repo) or use the hosted version at colivara.com.
- Obtain an API key by signing up at ColiVara or from your self-hosted API.
Example Code
import os
from colivara_py import ColiVara
rag_client = ColiVara(
api_key=os.environ.get("COLIVARA_API_KEY"), # Default is `None`
base_url="https://api.colivara.com" # Default is `https://api.colivara.com`
)
# Create a new collection (optional)
new_collection = rag_client.create_collection(name="my_collection", metadata={"description": "A sample collection"})
print(f"Created collection: {new_collection.name}")
# Upload a document to the collection
document = rag_client.upsert_document(
name="sample_document",
collection_name="my_collection", # Defaults to "default_collection"
url="https://example.com/sample.pdf",
metadata={"author": "John Doe"}
)
print(f"Uploaded document: {document.name}")
# Search for documents
search_results = rag_client.search(
query="machine learning",
collection_name="my_collection",
top_k=3
)
for result in search_results.results:
print(f"Page {result.page_number} of {result.document_name}: Score {result.normalized_score}")
# List documents in a collection
documents = rag_client.list_documents(collection_name="my_collection")
for doc in documents:
print(f"Document: {doc.name}, Pages: {doc.num_pages}")
# Generate embeddings
embeddings = rag_client.create_embedding(
input_data=["This is a sample text for embedding"],
task="query"
)
print(f"Generated {len(embeddings.data)} embeddings")
# Delete a document
rag_client.delete_document("sample_document", collection_name="my_collection")
print("Document deleted")
Development
Setting up the Development Environment
-
Clone the repository and navigate to the project directory:
cd colivara-py
-
Create a virtual environment:
uv venv -
Activate the virtual environment:
macOS/Linux:
source .venv/bin/activate
Windows:
.venv\Scripts\activate
-
Install the development dependencies:
uv sync --extra dev-dependencies
-
Run tests:
pytest
Regenerating the SDK
If the OpenAPI specification is updated, regenerate the SDK as follows:
-
Install the OpenAPI generator (on macOS, use Homebrew):
brew install openapi-generator
-
Verify the installation:
openapi-generator version -
Run the OpenAPI generator from the project directory:
openapi-generator generate -i https://api.colivara.com/v1/openapi.json -g python -c config.yaml --ignore-file-override .openapi-generator-ignore --template-dir ./templates
Updating the SDK and Documentation
Follow these steps for major changes to the OpenAPI spec:
- Regenerate the SDK using the OpenAPI generator.
- Update the client interface in
colivara_py/client.py. if needed - Modify tests in the
testsdirectory to reflect the changes. if needed. - Run tests to ensure functionality.
Building Documentation Locally
Generate and view the SDK documentation:
-
To serve the documentation locally:
pdocs server colivara_py
-
To generate documentation as HTML:
pdocs as_html colivara_py --overwrite
-
To generate documentation as Markdown:
pdocs as_markdown colivara_py
License
This SDK is licensed under the Apache License, Version 2.0. The ColiVara API is licensed under the Functional Source License, Version 1.1, Apache 2.0 Future License. See LICENSE.md for details.
For commercial licensing, contact us via tjmlabs.com. We’re happy to work with you to provide a license tailored to your needs.
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 colivara_py-1.5.1.tar.gz.
File metadata
- Download URL: colivara_py-1.5.1.tar.gz
- Upload date:
- Size: 38.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81227c57fe7da23820ab4d17aeeaab42ce7f3d8ce5875b4daf7da401d7b67eb8
|
|
| MD5 |
f844eeb2fcb00fb7047a74adb970ecc1
|
|
| BLAKE2b-256 |
811349046608364ce75f5f6438bd986ceed5485b15684f6d1886a9200b7a8a8d
|
Provenance
The following attestation bundles were made for colivara_py-1.5.1.tar.gz:
Publisher:
publish.yml on tjmlabs/colivara-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
colivara_py-1.5.1.tar.gz -
Subject digest:
81227c57fe7da23820ab4d17aeeaab42ce7f3d8ce5875b4daf7da401d7b67eb8 - Sigstore transparency entry: 157885867
- Sigstore integration time:
-
Permalink:
tjmlabs/colivara-py@b070cdbc7060629e8e4dea9a54c6b6703c1d7c90 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tjmlabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b070cdbc7060629e8e4dea9a54c6b6703c1d7c90 -
Trigger Event:
pull_request
-
Statement type:
File details
Details for the file colivara_py-1.5.1-py3-none-any.whl.
File metadata
- Download URL: colivara_py-1.5.1-py3-none-any.whl
- Upload date:
- Size: 30.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
304b7c4f63ee69c60361efd0973dd8d325e9f98e1a91f34d30e73169a9455805
|
|
| MD5 |
c51c49b91ab5287f135127265fc4064f
|
|
| BLAKE2b-256 |
b9643e52df572d45ab35966d597e2b0a6449ecb5172be136b86647a9fb2aee30
|
Provenance
The following attestation bundles were made for colivara_py-1.5.1-py3-none-any.whl:
Publisher:
publish.yml on tjmlabs/colivara-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
colivara_py-1.5.1-py3-none-any.whl -
Subject digest:
304b7c4f63ee69c60361efd0973dd8d325e9f98e1a91f34d30e73169a9455805 - Sigstore transparency entry: 157885868
- Sigstore integration time:
-
Permalink:
tjmlabs/colivara-py@b070cdbc7060629e8e4dea9a54c6b6703c1d7c90 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tjmlabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b070cdbc7060629e8e4dea9a54c6b6703c1d7c90 -
Trigger Event:
pull_request
-
Statement type: