Morphik Python Client
Project description
Morphik
A Python client for Morphik API that enables document ingestion, semantic search, and retrieval augmented generation capabilities.
Installation
pip install morphik
Usage
The SDK provides both synchronous and asynchronous clients:
Synchronous Usage
from morphik import Morphik
# Initialize client - connects to localhost:8000 by default
db = Morphik()
# Or with authentication URI (for production)
# db = Morphik("morphik://owner_id:token@api.morphik.ai")
# Ingest a text document
doc = db.ingest_text(
content="Your document content",
metadata={"title": "Example Document"}
)
# Ingest a file
doc = db.ingest_file(
file="path/to/document.pdf",
metadata={"category": "reports"}
)
# Retrieve relevant chunks
chunks = db.retrieve_chunks(
query="Your search query",
filters={"category": "reports"}
)
# Query with RAG
response = db.query(
query="Summarize the key points in the document",
filters={"category": "reports"}
)
print(response.completion)
Asynchronous Usage
import asyncio
from morphik.async_ import AsyncMorphik
async def main():
# Initialize async client - connects to localhost:8000 by default
async with AsyncMorphik() as db:
# Or with authentication URI (for production)
# async with AsyncMorphik("morphik://owner_id:token@api.morphik.ai") as db:
# Ingest a text document
doc = await db.ingest_text(
content="Your document content",
metadata={"title": "Example Document"}
)
# Query with RAG
response = await db.query(
query="Summarize the key points in the document",
)
print(response.completion)
# Run the async function
asyncio.run(main())
Features
- Document ingestion (text, files, directories)
- Semantic search and retrieval
- Retrieval-augmented generation (RAG)
- Knowledge graph creation and querying
- Multi-user and multi-folder scoping
- Metadata filtering
- Document management
Development
Running Tests
To run the tests, first install the development dependencies:
pip install -r test_requirements.txt
Then run the tests:
# Run all tests (requires a running Morphik server)
pytest morphik/tests/ -v
# Run specific test modules
pytest morphik/tests/test_sync.py -v
pytest morphik/tests/test_async.py -v
# Skip tests if you don't have a running server
SKIP_LIVE_TESTS=1 pytest morphik/tests/ -v
# Specify a custom server URL for tests
MORPHIK_TEST_URL=http://custom-server:8000 pytest morphik/tests/ -v
Example Usage Script
The SDK comes with an example script that demonstrates basic usage:
# Run synchronous example
python -m morphik.tests.example_usage
# Run asynchronous example
python -m morphik.tests.example_usage --async
The example script demonstrates:
- Text and file ingestion
- Creating folders and user scopes
- Retrieving chunks and documents
- Generating completions using RAG
- Batch operations and cleanup
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 morphik-0.2.0.tar.gz.
File metadata
- Download URL: morphik-0.2.0.tar.gz
- Upload date:
- Size: 43.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3af6fe0539e8a9ec2b48778a3e79e2f4657957e28de9144c917d31736f8d2171
|
|
| MD5 |
5accc5f1e83aa181edb370f46dcba4ae
|
|
| BLAKE2b-256 |
892abe8ccbf0c115fa1df297588d2a4dd2f992feee087fcc761e9888009c9246
|
File details
Details for the file morphik-0.2.0-py3-none-any.whl.
File metadata
- Download URL: morphik-0.2.0-py3-none-any.whl
- Upload date:
- Size: 52.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fad9c9c52d73ba766e392a77843eaa6b44b5d8dd8ca754fa85dfc631e8329b3
|
|
| MD5 |
a61700e9262e324762b57c8b21300cc5
|
|
| BLAKE2b-256 |
a2c3cda14a02ef4e14ab05775108f9577e748ecccc9cdc400cd64ef8dbd9997f
|