Python client for OramaCore and Orama Cloud
Project description
Orama Python Client
Python client for OramaCore and Orama Cloud.
Installation
Basic Installation
pip install oramacore-client
From Source
git clone https://github.com/oramasearch/oramacore-client-python.git
cd oramacore-client-python
pip install -e .
Development Installation
git clone https://github.com/oramasearch/oramacore-client-python.git
cd oramacore-client-python
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install -e .
Production Installation
For production deployments with pinned versions:
pip install -r requirements-prod.txt
Optional Features
For enhanced functionality (caching, monitoring, performance):
pip install -r requirements-optional.txt
Installation Helper
You can also use the provided installation script for easier setup:
# Basic installation
python install.py basic
# Development installation
python install.py dev
# Production installation
python install.py prod
# With optional features
python install.py optional
# Everything (dev + optional)
python install.py all
Quick Start
Basic Usage
import asyncio
from orama import CollectionManager, SearchParams
async def main():
# Initialize the collection manager
manager = CollectionManager({
"collection_id": "your-collection-id",
"api_key": "your-api-key"
})
# Perform a search
results = await manager.search(SearchParams(
term="search query",
limit=10
))
print(f"Found {results.count} results")
for hit in results.hits:
print(f"Score: {hit.score}, Document: {hit.document}")
# Close the manager
await manager.close()
# Run the async function
asyncio.run(main())
Collection Management
import asyncio
from orama import OramaCoreManager, CreateCollectionParams
async def main():
# Initialize the core manager
manager = OramaCoreManager({
"url": "https://your-orama-instance.com",
"master_api_key": "your-master-key"
})
# Create a new collection
collection = await manager.collection.create(
CreateCollectionParams(
id="my-collection",
description="My search collection"
)
)
print(f"Created collection: {collection.id}")
asyncio.run(main())
Document Management
import asyncio
from orama import CollectionManager
async def main():
manager = CollectionManager({
"collection_id": "your-collection-id",
"api_key": "your-api-key"
})
# Get an index reference
index = manager.index.set("your-index-id")
# Insert documents
await index.insert_documents([
{"id": "1", "title": "Document 1", "content": "Content 1"},
{"id": "2", "title": "Document 2", "content": "Content 2"}
])
# Update documents
await index.upsert_documents([
{"id": "1", "title": "Updated Document 1", "content": "Updated content"}
])
# Delete documents
await index.delete_documents(["2"])
await manager.close()
asyncio.run(main())
AI-Powered Search
import asyncio
from orama import CollectionManager, NLPSearchParams
async def main():
manager = CollectionManager({
"collection_id": "your-collection-id",
"api_key": "your-api-key"
})
# Perform NLP search
results = await manager.ai.nlp_search(
NLPSearchParams(
query="What are the benefits of renewable energy?"
)
)
print("NLP Search results:", results)
# Create an AI session for conversational search
session = manager.ai.create_ai_session()
# Stream an answer
async for chunk in session.answer_stream({
"query": "Explain machine learning in simple terms"
}):
print(chunk, end="", flush=True)
await manager.close()
asyncio.run(main())
Cloud Integration
import asyncio
from orama import OramaCloud
async def main():
# Initialize Orama Cloud client
cloud = OramaCloud({
"project_id": "your-project-id",
"api_key": "your-api-key"
})
# Search across datasources
results = await cloud.search({
"term": "search query",
"datasources": ["datasource-1", "datasource-2"]
})
print(f"Found {results.count} results")
# Manage a specific datasource
datasource = cloud.data_source("datasource-1")
await datasource.insert_documents([
{"title": "New document", "content": "Document content"}
])
await cloud.close()
asyncio.run(main())
API Reference
CollectionManager
Main class for interacting with Orama collections.
Methods
search(params: SearchParams) -> SearchResult: Perform a searchai.nlp_search(params: NLPSearchParams) -> List[Dict]: NLP-powered searchai.create_ai_session(config?) -> OramaCoreStream: Create AI sessionindex.set(id: str) -> Index: Get index referenceclose(): Close the manager
OramaCoreManager
Class for managing Orama collections at the cluster level.
Methods
collection.create(params: CreateCollectionParams) -> NewCollectionResponse: Create collectioncollection.list() -> List[GetCollectionsResponse]: List collectionscollection.get(id: str) -> GetCollectionsResponse: Get collectioncollection.delete(id: str): Delete collection
OramaCloud
High-level client for Orama Cloud.
Methods
search(params: Dict) -> SearchResult: Search across datasourcesdata_source(id: str) -> DataSourceNamespace: Get datasource reference
Index
Class for managing documents in an index.
Methods
insert_documents(docs: Union[Dict, List[Dict]]): Insert documentsupsert_documents(docs: List[Dict]): Upsert documentsdelete_documents(ids: Union[str, List[str]]): Delete documentsreindex(): Reindex the collection
Configuration
Authentication
The client supports two authentication methods:
- API Key Authentication: Use your collection's API key
- Private API Key (JWT): Use a private API key that starts with
p_
Environment Variables
You can also configure the client using environment variables:
ORAMA_API_KEY: Your API keyORAMA_COLLECTION_ID: Your collection IDORAMA_ENDPOINT: Custom endpoint URL
Server-Side Usage
This client is designed specifically for server-side use in Python applications. It does not include browser-specific functionality like localStorage or sendBeacon. All user identification is handled through API keys and server-generated UUIDs.
Error Handling
import asyncio
from orama import CollectionManager, SearchParams
async def main():
manager = CollectionManager({
"collection_id": "your-collection-id",
"api_key": "your-api-key"
})
try:
results = await manager.search(SearchParams(term="query"))
print(results)
except Exception as e:
print(f"Search failed: {e}")
finally:
await manager.close()
asyncio.run(main())
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the AGPLv3 License - see the LICENSE file for details.
Support
- Documentation: https://docs.orama.com
- GitHub Issues: https://github.com/oramasearch/oramacore-client-python/issues
- Community: https://orama.to/slack
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 oramacore_client-1.2.0.tar.gz.
File metadata
- Download URL: oramacore_client-1.2.0.tar.gz
- Upload date:
- Size: 66.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3350c9d7f0aa3f8e49e6c54722722d02e552dbba091d2cfdee2f7f9fe1faf88
|
|
| MD5 |
eb947b699a1077ca177d301bf713e30c
|
|
| BLAKE2b-256 |
d561a1e082e605d07e3062d5a8caeebdda13c00ba11214bd7354da8a587dc77b
|
File details
Details for the file oramacore_client-1.2.0-py3-none-any.whl.
File metadata
- Download URL: oramacore_client-1.2.0-py3-none-any.whl
- Upload date:
- Size: 49.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6c53d3c347e784ddd18deaea0fffa2b97cc9ea1ce3be43794c38f86706f3b63
|
|
| MD5 |
c9bf783916ad1ee11d889fb5fb0005ad
|
|
| BLAKE2b-256 |
48d2c25004d24f8aac493b098bd7c96f40f4eb773ca4494825148baef09f1658
|