Memic Python SDK
Official Python SDK for the Memic Context Engineering API.
Upload documents, process them into searchable chunks, and perform semantic search with metadata filters.
Installation
pip install memic
Quick Start
from memic import Memic, MetadataFilters, PageRange
# Initialize client (uses MEMIC_API_KEY env var if not provided)
client = Memic(api_key="mk_...")
# List projects
projects = client.list_projects()
for p in projects:
print(f"{p.name}: {p.id}")
# Upload a file (waits for processing by default)
file = client.upload_file(
project_id="your-project-id",
file_path="/path/to/document.pdf",
reference_id="lesson_123" # Optional: for linking with external systems
)
print(f"Uploaded: {file.id}, status: {file.status}")
# Search with filters
results = client.search(
query="key findings about climate change",
project_id="your-project-id",
top_k=10,
min_score=0.7,
filters=MetadataFilters(
reference_id="TG_G1_Math",
page_range=PageRange(gte=1, lte=50)
)
)
for result in results:
print(f"[{result.score:.2f}] {result.file_name} (p.{result.page_number})")
print(f" {result.content[:200]}...")
Features
- File Upload: 3-step presigned URL flow for efficient uploads
- Wait for Ready: Automatic polling until file processing completes
- Semantic Search: Vector similarity search with rich metadata
- Metadata Filters: Filter by reference_id, page numbers, categories
- Simple API: Single client class, no complex patterns
Configuration
API Key
Set your API key via environment variable or constructor:
export MEMIC_API_KEY=mk_your_api_key_here
# Or pass directly
client = Memic(api_key="mk_...")
Custom Base URL
For development or self-hosted deployments:
client = Memic(
api_key="mk_...",
base_url="https://your-api.example.com"
)
API Reference
Memic Client
client = Memic(
api_key: str = None, # Uses MEMIC_API_KEY env var if not provided
base_url: str = None, # Default: https://api.memic.ai
timeout: int = 30 # Request timeout in seconds
)
Methods
list_projects() -> List[Project]
List all projects in your organization.
upload_file(project_id, file_path, ...) -> File
Upload a file to a project.
| Parameter | Type | Default | Description |
|---|---|---|---|
project_id |
str | required | Target project ID |
file_path |
str/Path | required | Path to file |
wait_for_ready |
bool | True | Wait for processing to complete |
reference_id |
str | None | External reference ID |
metadata |
dict | None | Custom metadata |
poll_interval |
float | 2.0 | Seconds between status checks |
poll_timeout |
float | 300 | Max wait time in seconds |
get_file_status(project_id, file_id) -> File
Get current processing status of a file.
search(query, ...) -> SearchResults
Search for content across documents.
| Parameter | Type | Default | Description |
|---|---|---|---|
query |
str | required | Search query |
project_id |
str | None | Limit to project |
file_ids |
List[str] | None | Limit to specific files |
top_k |
int | 10 | Number of results |
min_score |
float | 0.7 | Minimum similarity score |
filters |
MetadataFilters | None | Metadata filters |
Types
FileStatus
Enum with processing states:
UPLOADING,UPLOADED,UPLOAD_FAILEDCONVERSION_STARTED,CONVERSION_COMPLETE,CONVERSION_FAILEDPARSING_STARTED,PARSING_COMPLETE,PARSING_FAILEDCHUNKING_STARTED,CHUNKING_COMPLETE,CHUNKING_FAILEDEMBEDDING_STARTED,EMBEDDING_COMPLETE,EMBEDDING_FAILEDREADY
Properties:
.is_failed- True if status indicates failure.is_processing- True if still processing
MetadataFilters
MetadataFilters(
reference_id: str = None, # Filter by reference ID
reference_ids: List[str] = None, # Multiple reference IDs (OR)
page_number: int = None, # Exact page match
page_numbers: List[int] = None, # Multiple pages (OR)
page_range: PageRange = None, # Page range
category: str = None, # Category filter
document_type: str = None # Document type filter
)
Exceptions
from memic import MemicError, AuthenticationError, NotFoundError, APIError
try:
results = client.search(query="test")
except AuthenticationError:
print("Invalid API key")
except NotFoundError:
print("Resource not found")
except APIError as e:
print(f"API error: {e.status_code} - {e.message}")
except MemicError as e:
print(f"Error: {e.message}")
Development
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/
# Type check
mypy src/memic/
# Lint
ruff check src/
License
MIT License - see LICENSE for details.
Metadata
Release files for memic 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| memic-0.4.0.tar.gz | 12.1 kB | Without provenance | Details for memic-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| memic-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for memic-0.4.0-py3-none-any.whl |
Total release size: 26.0 kB
Release files / memic-0.4.0.tar.gz
| Download URL | memic-0.4.0.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14fc0a437142b7034ffadd71d47675c4f4b9656c229155e17922883756ef7f14
|
|
BLAKE2b-256 checksum How to use checksums |
e93fa1fbcaf30d5e72ebd396ca51216ef7b664336da6da992b60ac6907d04590
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / memic-0.4.0-py3-none-any.whl
| Download URL | memic-0.4.0-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a50db38c8641dd528b23617dcb9f2203682584daef327209a01d1772c1b33be2
|
|
BLAKE2b-256 checksum How to use checksums |
4f2f198ae250a7080eccaae2f9aee0cd974be623832f4b392c47febf55bc49a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for memic 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.