mygramdb-client 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. mygramdb_client-1.0.0/.flake8 +3 -0
  2. mygramdb_client-1.0.0/.github/workflows/ci.yml +48 -0
  3. mygramdb_client-1.0.0/.github/workflows/publish.yml +50 -0
  4. mygramdb_client-1.0.0/.gitignore +11 -0
  5. mygramdb_client-1.0.0/.python-version +1 -0
  6. mygramdb_client-1.0.0/LICENSE +21 -0
  7. mygramdb_client-1.0.0/PKG-INFO +145 -0
  8. mygramdb_client-1.0.0/README.md +118 -0
  9. mygramdb_client-1.0.0/README_ja.md +118 -0
  10. mygramdb_client-1.0.0/docs/en/advanced-usage.md +526 -0
  11. mygramdb_client-1.0.0/docs/en/api-reference.md +421 -0
  12. mygramdb_client-1.0.0/docs/en/getting-started.md +245 -0
  13. mygramdb_client-1.0.0/docs/en/search-expression.md +175 -0
  14. mygramdb_client-1.0.0/docs/ja/advanced-usage.md +517 -0
  15. mygramdb_client-1.0.0/docs/ja/api-reference.md +421 -0
  16. mygramdb_client-1.0.0/docs/ja/getting-started.md +245 -0
  17. mygramdb_client-1.0.0/docs/ja/search-expression.md +175 -0
  18. mygramdb_client-1.0.0/pyproject.toml +59 -0
  19. mygramdb_client-1.0.0/requirements-dev.lock +37 -0
  20. mygramdb_client-1.0.0/requirements.lock +12 -0
  21. mygramdb_client-1.0.0/src/mygramdb_client/__init__.py +88 -0
  22. mygramdb_client-1.0.0/src/mygramdb_client/client.py +909 -0
  23. mygramdb_client-1.0.0/src/mygramdb_client/command_utils.py +157 -0
  24. mygramdb_client-1.0.0/src/mygramdb_client/errors.py +45 -0
  25. mygramdb_client-1.0.0/src/mygramdb_client/search_expression.py +358 -0
  26. mygramdb_client-1.0.0/src/mygramdb_client/types.py +156 -0
  27. mygramdb_client-1.0.0/tests/__init__.py +1 -0
  28. mygramdb_client-1.0.0/tests/test_client.py +654 -0
  29. mygramdb_client-1.0.0/tests/test_command_utils.py +170 -0
  30. mygramdb_client-1.0.0/tests/test_e2e.py +431 -0
  31. mygramdb_client-1.0.0/tests/test_integration.py +242 -0
  32. mygramdb_client-1.0.0/tests/test_protocol.py +553 -0
  33. mygramdb_client-1.0.0/tests/test_search_expression.py +160 -0
@@ -0,0 +1,3 @@
1
+ [flake8]
2
+ max-line-length = 120
3
+ exclude = .git,__pycache__,build,dist,.venv
@@ -0,0 +1,48 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ tags-ignore: ['**']
7
+ paths-ignore:
8
+ - '**.md'
9
+ - 'docs/**'
10
+ - 'LICENSE'
11
+ pull_request:
12
+ branches: [main]
13
+ paths-ignore:
14
+ - '**.md'
15
+ - 'docs/**'
16
+ - 'LICENSE'
17
+
18
+ jobs:
19
+ lint:
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ - uses: actions/setup-python@v5
24
+ with:
25
+ python-version: '3.12'
26
+ - run: pip install flake8
27
+ - run: flake8 src tests --max-line-length=100
28
+
29
+ test:
30
+ runs-on: ${{ matrix.os }}
31
+ strategy:
32
+ matrix:
33
+ os: [ubuntu-latest, macos-latest]
34
+ python-version: ['3.9', '3.12', '3.13']
35
+ steps:
36
+ - uses: actions/checkout@v4
37
+ - uses: actions/setup-python@v5
38
+ with:
39
+ python-version: ${{ matrix.python-version }}
40
+ - run: pip install -e ".[dev]" || pip install -e . && pip install pytest pytest-asyncio pytest-cov
41
+ - name: Run tests with coverage
42
+ run: pytest tests/ --ignore=tests/test_e2e.py --cov=mygramdb_client --cov-report=xml -q
43
+ - name: Upload coverage to Codecov
44
+ if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
45
+ uses: codecov/codecov-action@v5
46
+ with:
47
+ token: ${{ secrets.CODECOV_TOKEN }}
48
+ files: coverage.xml
@@ -0,0 +1,50 @@
1
+ name: Publish and Create Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*.*.*'
7
+
8
+ permissions:
9
+ contents: write
10
+ id-token: write
11
+
12
+ jobs:
13
+ publish:
14
+ runs-on: ubuntu-latest
15
+ environment:
16
+ name: pypi
17
+ url: https://pypi.org/p/mygramdb-client
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+
21
+ - uses: actions/setup-python@v5
22
+ with:
23
+ python-version: '3.12'
24
+
25
+ - run: pip install build
26
+
27
+ - name: Lint
28
+ run: pip install flake8 && flake8 src tests --max-line-length=100
29
+
30
+ - name: Test
31
+ run: |
32
+ pip install -e . && pip install pytest pytest-asyncio
33
+ pytest tests/ --ignore=tests/test_e2e.py -q
34
+
35
+ - name: Build package
36
+ run: python -m build
37
+
38
+ - name: Create GitHub Release
39
+ uses: softprops/action-gh-release@v2
40
+ with:
41
+ name: Release ${{ github.ref_name }}
42
+ tag_name: ${{ github.ref_name }}
43
+ generate_release_notes: true
44
+ env:
45
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46
+
47
+ - name: Publish to PyPI
48
+ uses: pypa/gh-action-pypi-publish@release/v1
49
+ with:
50
+ attestations: true
@@ -0,0 +1,11 @@
1
+ # python generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # venv
10
+ .venv
11
+ .claude/
@@ -0,0 +1 @@
1
+ 3.12.9
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 libraz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,145 @@
1
+ Metadata-Version: 2.4
2
+ Name: mygramdb-client
3
+ Version: 1.0.0
4
+ Summary: Python client for MygramDB - high-performance in-memory full-text search engine with MySQL replication support
5
+ Project-URL: Homepage, https://github.com/libraz/python-mygramdb-client
6
+ Project-URL: Repository, https://github.com/libraz/python-mygramdb-client
7
+ Project-URL: Issues, https://github.com/libraz/python-mygramdb-client/issues
8
+ Author-email: libraz <libraz@libraz.net>
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: asyncio,client,database,full-text-search,mygramdb
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Framework :: AsyncIO
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Database
23
+ Classifier: Topic :: Text Processing :: Indexing
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.9
26
+ Description-Content-Type: text/markdown
27
+
28
+ # python-mygramdb-client
29
+
30
+ [![CI](https://img.shields.io/github/actions/workflow/status/libraz/python-mygramdb-client/ci.yml?branch=main&label=CI)](https://github.com/libraz/python-mygramdb-client/actions)
31
+ [![codecov](https://codecov.io/gh/libraz/python-mygramdb-client/branch/main/graph/badge.svg)](https://codecov.io/gh/libraz/python-mygramdb-client)
32
+ [![Python](https://img.shields.io/badge/python-%E2%89%A53.9-3776AB?logo=python&logoColor=white)](https://www.python.org/)
33
+ [![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
34
+ [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)](https://github.com/libraz/python-mygramdb-client)
35
+
36
+ Python client library for [MygramDB](https://github.com/libraz/mygram-db/) — a high-performance in-memory full-text search engine with MySQL replication support.
37
+
38
+ ## Overview
39
+
40
+ 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.
41
+
42
+ | | MySQL FULLTEXT | MygramDB |
43
+ |---|---|---|
44
+ | **Search Speed** | Baseline | 25-200x faster |
45
+ | **Storage** | On-disk | In-memory |
46
+ | **Replication** | — | MySQL binlog |
47
+ | **Protocol** | MySQL | TCP (memcached-style) |
48
+
49
+ ### Features
50
+
51
+ - **Zero Dependencies** — Standard library only
52
+ - **Async/Await API** — Modern asyncio-based interface with context manager support
53
+ - **Search Expression Parser** — Web-style search syntax (+required, -excluded, "phrase", OR, grouping)
54
+ - **Full Protocol Support** — All MygramDB commands (SEARCH, COUNT, GET, INFO, CACHE, DUMP, OPTIMIZE, etc.)
55
+ - **Type Safety** — Full type hints with dataclasses
56
+ - **Input Validation** — Built-in protection against control character injection
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ pip install mygramdb-client
62
+ ```
63
+
64
+ ### From source
65
+
66
+ ```bash
67
+ git clone https://github.com/libraz/python-mygramdb-client.git
68
+ cd python-mygramdb-client
69
+ rye sync
70
+ ```
71
+
72
+ ## Quick Start
73
+
74
+ ```python
75
+ import asyncio
76
+ from mygramdb_client import MygramClient, ClientConfig, SearchOptions
77
+
78
+ async def main():
79
+ async with MygramClient(ClientConfig(host='localhost', port=11016)) as client:
80
+ # Search
81
+ results = await client.search('articles', 'hello', SearchOptions(limit=100))
82
+ print(f"Found {results.total_count} results")
83
+
84
+ # Count
85
+ count = await client.count('articles', 'technology')
86
+ print(f"Count: {count.count}")
87
+
88
+ # Get document by ID
89
+ doc = await client.get('articles', '12345')
90
+ print(f"Doc: {doc.primary_key} {doc.fields}")
91
+
92
+ asyncio.run(main())
93
+ ```
94
+
95
+ ## Search Expressions
96
+
97
+ Parse web-style search queries into structured search parameters:
98
+
99
+ ```python
100
+ from mygramdb_client import simplify_search_expression
101
+
102
+ # Space = AND, - = NOT, "" = phrase, OR = OR, () = grouping
103
+ expr = simplify_search_expression('hello world -spam')
104
+ # expr = SimplifiedExpression(main_term='hello', and_terms=['world'], not_terms=['spam'])
105
+
106
+ results = await client.search('articles', expr.main_term, SearchOptions(
107
+ and_terms=expr.and_terms,
108
+ not_terms=expr.not_terms,
109
+ limit=100,
110
+ offset=50,
111
+ filters={'status': 'published', 'lang': 'en'},
112
+ sort_column='created_at',
113
+ sort_desc=True,
114
+ ))
115
+ ```
116
+
117
+ ## Type Hints
118
+
119
+ Full type definitions are included:
120
+
121
+ ```python
122
+ from mygramdb_client import (
123
+ ClientConfig,
124
+ SearchResponse,
125
+ CountResponse,
126
+ Document,
127
+ ServerInfo,
128
+ SearchOptions,
129
+ DumpStatus,
130
+ CacheStats,
131
+ )
132
+ ```
133
+
134
+ ## Development
135
+
136
+ ```bash
137
+ rye sync # Install dependencies
138
+ rye run pytest # Run tests
139
+ rye run pytest -v # Run tests (verbose)
140
+ rye run flake8 src tests # Lint
141
+ ```
142
+
143
+ ## License
144
+
145
+ [MIT](LICENSE)
@@ -0,0 +1,118 @@
1
+ # python-mygramdb-client
2
+
3
+ [![CI](https://img.shields.io/github/actions/workflow/status/libraz/python-mygramdb-client/ci.yml?branch=main&label=CI)](https://github.com/libraz/python-mygramdb-client/actions)
4
+ [![codecov](https://codecov.io/gh/libraz/python-mygramdb-client/branch/main/graph/badge.svg)](https://codecov.io/gh/libraz/python-mygramdb-client)
5
+ [![Python](https://img.shields.io/badge/python-%E2%89%A53.9-3776AB?logo=python&logoColor=white)](https://www.python.org/)
6
+ [![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
7
+ [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)](https://github.com/libraz/python-mygramdb-client)
8
+
9
+ Python client library for [MygramDB](https://github.com/libraz/mygram-db/) — a high-performance in-memory full-text search engine with MySQL replication support.
10
+
11
+ ## Overview
12
+
13
+ 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.
14
+
15
+ | | MySQL FULLTEXT | MygramDB |
16
+ |---|---|---|
17
+ | **Search Speed** | Baseline | 25-200x faster |
18
+ | **Storage** | On-disk | In-memory |
19
+ | **Replication** | — | MySQL binlog |
20
+ | **Protocol** | MySQL | TCP (memcached-style) |
21
+
22
+ ### Features
23
+
24
+ - **Zero Dependencies** — Standard library only
25
+ - **Async/Await API** — Modern asyncio-based interface with context manager support
26
+ - **Search Expression Parser** — Web-style search syntax (+required, -excluded, "phrase", OR, grouping)
27
+ - **Full Protocol Support** — All MygramDB commands (SEARCH, COUNT, GET, INFO, CACHE, DUMP, OPTIMIZE, etc.)
28
+ - **Type Safety** — Full type hints with dataclasses
29
+ - **Input Validation** — Built-in protection against control character injection
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install mygramdb-client
35
+ ```
36
+
37
+ ### From source
38
+
39
+ ```bash
40
+ git clone https://github.com/libraz/python-mygramdb-client.git
41
+ cd python-mygramdb-client
42
+ rye sync
43
+ ```
44
+
45
+ ## Quick Start
46
+
47
+ ```python
48
+ import asyncio
49
+ from mygramdb_client import MygramClient, ClientConfig, SearchOptions
50
+
51
+ async def main():
52
+ async with MygramClient(ClientConfig(host='localhost', port=11016)) as client:
53
+ # Search
54
+ results = await client.search('articles', 'hello', SearchOptions(limit=100))
55
+ print(f"Found {results.total_count} results")
56
+
57
+ # Count
58
+ count = await client.count('articles', 'technology')
59
+ print(f"Count: {count.count}")
60
+
61
+ # Get document by ID
62
+ doc = await client.get('articles', '12345')
63
+ print(f"Doc: {doc.primary_key} {doc.fields}")
64
+
65
+ asyncio.run(main())
66
+ ```
67
+
68
+ ## Search Expressions
69
+
70
+ Parse web-style search queries into structured search parameters:
71
+
72
+ ```python
73
+ from mygramdb_client import simplify_search_expression
74
+
75
+ # Space = AND, - = NOT, "" = phrase, OR = OR, () = grouping
76
+ expr = simplify_search_expression('hello world -spam')
77
+ # expr = SimplifiedExpression(main_term='hello', and_terms=['world'], not_terms=['spam'])
78
+
79
+ results = await client.search('articles', expr.main_term, SearchOptions(
80
+ and_terms=expr.and_terms,
81
+ not_terms=expr.not_terms,
82
+ limit=100,
83
+ offset=50,
84
+ filters={'status': 'published', 'lang': 'en'},
85
+ sort_column='created_at',
86
+ sort_desc=True,
87
+ ))
88
+ ```
89
+
90
+ ## Type Hints
91
+
92
+ Full type definitions are included:
93
+
94
+ ```python
95
+ from mygramdb_client import (
96
+ ClientConfig,
97
+ SearchResponse,
98
+ CountResponse,
99
+ Document,
100
+ ServerInfo,
101
+ SearchOptions,
102
+ DumpStatus,
103
+ CacheStats,
104
+ )
105
+ ```
106
+
107
+ ## Development
108
+
109
+ ```bash
110
+ rye sync # Install dependencies
111
+ rye run pytest # Run tests
112
+ rye run pytest -v # Run tests (verbose)
113
+ rye run flake8 src tests # Lint
114
+ ```
115
+
116
+ ## License
117
+
118
+ [MIT](LICENSE)
@@ -0,0 +1,118 @@
1
+ # python-mygramdb-client
2
+
3
+ [![CI](https://img.shields.io/github/actions/workflow/status/libraz/python-mygramdb-client/ci.yml?branch=main&label=CI)](https://github.com/libraz/python-mygramdb-client/actions)
4
+ [![codecov](https://codecov.io/gh/libraz/python-mygramdb-client/branch/main/graph/badge.svg)](https://codecov.io/gh/libraz/python-mygramdb-client)
5
+ [![Python](https://img.shields.io/badge/python-%E2%89%A53.9-3776AB?logo=python&logoColor=white)](https://www.python.org/)
6
+ [![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
7
+ [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)](https://github.com/libraz/python-mygramdb-client)
8
+
9
+ [MygramDB](https://github.com/libraz/mygram-db/) 用の Python クライアントライブラリ — MySQL レプリケーションをサポートする高性能インメモリ全文検索エンジン。
10
+
11
+ ## 概要
12
+
13
+ MygramDB は MySQL FULLTEXT の **25〜200倍高速** な全文検索を提供します。このクライアントは MygramDB の TCP テキストプロトコル(memcached スタイル)で通信し、外部依存はゼロです。
14
+
15
+ | | MySQL FULLTEXT | MygramDB |
16
+ |---|---|---|
17
+ | **検索速度** | ベースライン | 25〜200倍高速 |
18
+ | **ストレージ** | ディスク | インメモリ |
19
+ | **レプリケーション** | — | MySQL binlog |
20
+ | **プロトコル** | MySQL | TCP(memcached スタイル) |
21
+
22
+ ### 特徴
23
+
24
+ - **外部依存ゼロ** — 標準ライブラリのみ
25
+ - **Async/Await API** — コンテキストマネージャ対応のモダンな asyncio ベースインターフェース
26
+ - **検索式パーサー** — Web スタイルの検索構文(+必須、-除外、"フレーズ"、OR、グループ化)
27
+ - **完全なプロトコルサポート** — すべての MygramDB コマンド(SEARCH、COUNT、GET、INFO、CACHE、DUMP、OPTIMIZE など)
28
+ - **型安全性** — dataclass による完全な型ヒント
29
+ - **入力バリデーション** — 制御文字インジェクションに対する組み込み保護
30
+
31
+ ## インストール
32
+
33
+ ```bash
34
+ pip install mygramdb-client
35
+ ```
36
+
37
+ ### ソースからインストール
38
+
39
+ ```bash
40
+ git clone https://github.com/libraz/python-mygramdb-client.git
41
+ cd python-mygramdb-client
42
+ rye sync
43
+ ```
44
+
45
+ ## クイックスタート
46
+
47
+ ```python
48
+ import asyncio
49
+ from mygramdb_client import MygramClient, ClientConfig, SearchOptions
50
+
51
+ async def main():
52
+ async with MygramClient(ClientConfig(host='localhost', port=11016)) as client:
53
+ # 検索
54
+ results = await client.search('articles', 'hello', SearchOptions(limit=100))
55
+ print(f"{results.total_count} 件の結果が見つかりました")
56
+
57
+ # カウント
58
+ count = await client.count('articles', 'technology')
59
+ print(f"カウント: {count.count}")
60
+
61
+ # ID でドキュメントを取得
62
+ doc = await client.get('articles', '12345')
63
+ print(f"Doc: {doc.primary_key} {doc.fields}")
64
+
65
+ asyncio.run(main())
66
+ ```
67
+
68
+ ## 検索式
69
+
70
+ Web スタイルの検索クエリを構造化された検索パラメータにパースします:
71
+
72
+ ```python
73
+ from mygramdb_client import simplify_search_expression
74
+
75
+ # スペース = AND、- = NOT、"" = フレーズ、OR = OR、() = グループ化
76
+ expr = simplify_search_expression('hello world -spam')
77
+ # expr = SimplifiedExpression(main_term='hello', and_terms=['world'], not_terms=['spam'])
78
+
79
+ results = await client.search('articles', expr.main_term, SearchOptions(
80
+ and_terms=expr.and_terms,
81
+ not_terms=expr.not_terms,
82
+ limit=100,
83
+ offset=50,
84
+ filters={'status': 'published', 'lang': 'ja'},
85
+ sort_column='created_at',
86
+ sort_desc=True,
87
+ ))
88
+ ```
89
+
90
+ ## 型ヒント
91
+
92
+ 完全な型定義が含まれています:
93
+
94
+ ```python
95
+ from mygramdb_client import (
96
+ ClientConfig,
97
+ SearchResponse,
98
+ CountResponse,
99
+ Document,
100
+ ServerInfo,
101
+ SearchOptions,
102
+ DumpStatus,
103
+ CacheStats,
104
+ )
105
+ ```
106
+
107
+ ## 開発
108
+
109
+ ```bash
110
+ rye sync # 依存関係をインストール
111
+ rye run pytest # テストを実行
112
+ rye run pytest -v # テストを実行(詳細)
113
+ rye run flake8 src tests # リント
114
+ ```
115
+
116
+ ## ライセンス
117
+
118
+ [MIT](LICENSE)