Python client for MygramDB - high-performance in-memory full-text search engine with MySQL replication support
Project description
python-mygramdb-client
Python client library for MygramDB — a high-performance in-memory full-text search engine with MySQL replication support.
Compatible with MygramDB v1.6 (fuzzy search, highlight, facets, BM25).
Overview
MygramDB provides 25-200x faster full-text search than MySQL FULLTEXT. This client communicates via MygramDB's TCP text protocol (memcached-style) with zero external dependencies.
| MySQL FULLTEXT | MygramDB | |
|---|---|---|
| Search Speed | Baseline | 25-200x faster |
| Storage | On-disk | In-memory |
| Replication | — | MySQL binlog |
| Protocol | MySQL | TCP (memcached-style) |
Features
- Zero Dependencies — Standard library only
- Async/Await API — Modern asyncio-based interface with context manager support
- Search Expression Parser — Web-style search syntax (+required, -excluded, "phrase", OR, grouping)
- Full Protocol Support — All MygramDB commands (SEARCH, COUNT, GET, INFO, CACHE, DUMP, OPTIMIZE, etc.)
- Type Safety — Full type hints with dataclasses
- Input Validation — Built-in protection against control character injection
Installation
pip install mygramdb-client
From source
git clone https://github.com/libraz/python-mygramdb-client.git
cd python-mygramdb-client
rye sync
Quick Start
import asyncio
from mygramdb_client import MygramClient, ClientConfig, SearchOptions
async def main():
async with MygramClient(ClientConfig(host='localhost', port=11016)) as client:
# Search
results = await client.search('articles', 'hello', SearchOptions(limit=100))
print(f"Found {results.total_count} results")
# Count
count = await client.count('articles', 'technology')
print(f"Count: {count.count}")
# Get document by ID
doc = await client.get('articles', '12345')
print(f"Doc: {doc.primary_key} {doc.fields}")
asyncio.run(main())
Search Expressions
Parse web-style search queries into structured search parameters:
from mygramdb_client import simplify_search_expression
# Space = AND, - = NOT, "" = phrase, OR = OR, () = grouping
expr = simplify_search_expression('hello world -spam')
# expr = SimplifiedExpression(main_term='hello', and_terms=['world'], not_terms=['spam'])
results = await client.search('articles', expr.main_term, SearchOptions(
and_terms=expr.and_terms,
not_terms=expr.not_terms,
limit=100,
offset=50,
filters={'status': 'published', 'lang': 'en'},
sort_column='created_at',
sort_desc=True,
))
MygramDB v1.6 Features
from mygramdb_client import HighlightOptions, FacetOptions, SearchOptions
# BM25 relevance scoring
result = await client.search('articles', 'python',
SearchOptions(sort_column='_score', sort_desc=True))
# Fuzzy search (Levenshtein distance 1 or 2)
result = await client.search('articles', 'helo',
SearchOptions(fuzzy=1))
# Highlighted snippets
result = await client.search('articles', 'python',
SearchOptions(highlight=HighlightOptions(
open_tag='<mark>', close_tag='</mark>',
snippet_len=150, max_fragments=3,
)))
for r in result.results:
print(r.primary_key, r.snippet)
# Facet aggregation
facets = await client.facet('articles', 'category',
FacetOptions(query='python', limit=10))
for v in facets.results:
print(f'{v.value}: {v.count}')
Type Hints
Full type definitions are included:
from mygramdb_client import (
ClientConfig,
SearchResponse,
CountResponse,
Document,
ServerInfo,
SearchOptions,
DumpStatus,
CacheStats,
)
Development
rye sync # Install dependencies
rye run pytest # Run tests
rye run pytest -v # Run tests (verbose)
rye run flake8 src tests # Lint
License
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 mygramdb_client-1.1.1.tar.gz.
File metadata
- Download URL: mygramdb_client-1.1.1.tar.gz
- Upload date:
- Size: 57.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
900486e93900aba5503929e65d6743dd572a0549db351569dcefa939dda408f4
|
|
| MD5 |
cde3c74756127c697bad5c057960b405
|
|
| BLAKE2b-256 |
cc1ad1c27b269df441dc3ffd8f204c6fffa6db76a7787081c5f968186c2c8a82
|
Provenance
The following attestation bundles were made for mygramdb_client-1.1.1.tar.gz:
Publisher:
publish.yml on libraz/python-mygramdb-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mygramdb_client-1.1.1.tar.gz -
Subject digest:
900486e93900aba5503929e65d6743dd572a0549db351569dcefa939dda408f4 - Sigstore transparency entry: 1485237607
- Sigstore integration time:
-
Permalink:
libraz/python-mygramdb-client@9a0fbcad7027beab5677ed4f76f08054d5e25e24 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/libraz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9a0fbcad7027beab5677ed4f76f08054d5e25e24 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mygramdb_client-1.1.1-py3-none-any.whl.
File metadata
- Download URL: mygramdb_client-1.1.1-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
724eb6c7e2a0c5647f6d8e8bc45d1d93527434b7672e315b3d708bc4d3f7920f
|
|
| MD5 |
e9491438dbbff7be7d28a1cefaf8a28d
|
|
| BLAKE2b-256 |
07c072e7b24e4dba920dffa9753aca671f811c63a330e91d79390e24bbdb96af
|
Provenance
The following attestation bundles were made for mygramdb_client-1.1.1-py3-none-any.whl:
Publisher:
publish.yml on libraz/python-mygramdb-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mygramdb_client-1.1.1-py3-none-any.whl -
Subject digest:
724eb6c7e2a0c5647f6d8e8bc45d1d93527434b7672e315b3d708bc4d3f7920f - Sigstore transparency entry: 1485238023
- Sigstore integration time:
-
Permalink:
libraz/python-mygramdb-client@9a0fbcad7027beab5677ed4f76f08054d5e25e24 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/libraz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9a0fbcad7027beab5677ed4f76f08054d5e25e24 -
Trigger Event:
push
-
Statement type: