kiarina-lib-falkordb 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.
@@ -0,0 +1,39 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.so
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+ .ruff_cache/
9
+ .mypy_cache/
10
+ .pytest_cache/
11
+ .coverage
12
+ coverage.xml
13
+ htmlcov/
14
+
15
+ # uv
16
+ .uv_cache/
17
+
18
+ # Virtual environments & config
19
+ .venv/
20
+ .env
21
+
22
+ # IDE
23
+ .vscode/
24
+ *.code-workspace
25
+
26
+ # OS
27
+ .DS_Store
28
+
29
+ # Project specific
30
+ *.log
31
+ tmp/
32
+ ai.yaml
33
+
34
+ # Test data
35
+ tests/data/large/
36
+
37
+ # mise tasks (always include)
38
+ !mise-tasks/
39
+ !mise-tasks/**
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,27 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.0.0] - 2025-09-09
11
+
12
+ ### Added
13
+ - Initial release of kiarina-lib-falkordb
14
+ - FalkorDB client with configuration management using pydantic-settings-manager
15
+ - Connection pooling and caching
16
+ - Retry mechanism for connection failures
17
+ - Support for both sync and async operations (async prepared for future FalkorDB support)
18
+ - Type safety with full type hints and Pydantic validation
19
+ - Environment variable configuration support
20
+ - Runtime configuration overrides
21
+ - Multiple named configurations support
22
+
23
+ ### Dependencies
24
+ - falkordb (from kiarina/falkordb-py fork with redis6 support)
25
+ - pydantic-settings>=2.10.1
26
+ - pydantic-settings-manager>=2.1.0
27
+ - redis>=6.4.0
@@ -0,0 +1,280 @@
1
+ Metadata-Version: 2.4
2
+ Name: kiarina-lib-falkordb
3
+ Version: 1.0.0
4
+ Summary: FalkorDB client library for kiarina namespace
5
+ Project-URL: Homepage, https://github.com/kiarina/kiarina-python
6
+ Project-URL: Repository, https://github.com/kiarina/kiarina-python
7
+ Project-URL: Issues, https://github.com/kiarina/kiarina-python/issues
8
+ Project-URL: Changelog, https://github.com/kiarina/kiarina-python/blob/main/packages/kiarina-lib-falkordb/CHANGELOG.md
9
+ Project-URL: Documentation, https://github.com/kiarina/kiarina-python/tree/main/packages/kiarina-lib-falkordb#readme
10
+ Author-email: kiarina <kiarinadawa@gmail.com>
11
+ Maintainer-email: kiarina <kiarinadawa@gmail.com>
12
+ License: MIT
13
+ Keywords: client,database,falkordb,graph,pydantic,redis,settings
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Database
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.12
25
+ Requires-Dist: falkordb
26
+ Requires-Dist: pydantic-settings-manager>=2.1.0
27
+ Requires-Dist: pydantic-settings>=2.10.1
28
+ Requires-Dist: redis>=6.4.0
29
+ Description-Content-Type: text/markdown
30
+
31
+ # kiarina-lib-falkordb
32
+
33
+ A Python client library for [FalkorDB](https://falkordb.com/) with configuration management and connection pooling.
34
+
35
+ ## Features
36
+
37
+ - **Configuration Management**: Use `pydantic-settings-manager` for flexible configuration
38
+ - **Connection Pooling**: Automatic connection caching and reuse
39
+ - **Retry Support**: Built-in retry mechanism for connection failures
40
+ - **Sync & Async**: Support for both synchronous and asynchronous operations
41
+ - **Type Safety**: Full type hints and Pydantic validation
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ pip install kiarina-lib-falkordb
47
+ ```
48
+
49
+ ## Quick Start
50
+
51
+ ### Basic Usage (Sync)
52
+
53
+ ```python
54
+ from kiarina.lib.falkordb import get_falkordb
55
+
56
+ # Get a FalkorDB client with default settings
57
+ db = get_falkordb()
58
+
59
+ # Select a graph and run a query
60
+ graph = db.select_graph("social")
61
+ result = graph.query("CREATE (p:Person {name: 'Alice', age: 30}) RETURN p")
62
+ print(result.result_set)
63
+ ```
64
+
65
+ ### Async Usage
66
+
67
+ ```python
68
+ from kiarina.lib.falkordb.asyncio import get_falkordb
69
+
70
+ async def main():
71
+ # Get an async FalkorDB client
72
+ db = get_falkordb()
73
+
74
+ # Select a graph and run a query
75
+ graph = db.select_graph("social")
76
+ result = await graph.query("CREATE (p:Person {name: 'Bob', age: 25}) RETURN p")
77
+ print(result.result_set)
78
+ ```
79
+
80
+ ## Configuration
81
+
82
+ This library uses [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) for flexible configuration management.
83
+
84
+ ### Environment Variables
85
+
86
+ Configure the FalkorDB connection using environment variables:
87
+
88
+ ```bash
89
+ # FalkorDB connection URL
90
+ export KIARINA_LIB_FALKORDB_URL="falkor://localhost:6379"
91
+
92
+ # Enable retry mechanism
93
+ export KIARINA_LIB_FALKORDB_USE_RETRY="true"
94
+
95
+ # Timeout settings
96
+ export KIARINA_LIB_FALKORDB_SOCKET_TIMEOUT="6.0"
97
+ export KIARINA_LIB_FALKORDB_SOCKET_CONNECT_TIMEOUT="3.0"
98
+
99
+ # Retry settings
100
+ export KIARINA_LIB_FALKORDB_RETRY_ATTEMPTS="3"
101
+ export KIARINA_LIB_FALKORDB_RETRY_DELAY="1.0"
102
+ ```
103
+
104
+ ### Programmatic Configuration
105
+
106
+ ```python
107
+ from kiarina.lib.falkordb import settings_manager
108
+
109
+ # Configure for multiple environments
110
+ settings_manager.user_config = {
111
+ "development": {
112
+ "url": "falkor://localhost:6379",
113
+ "use_retry": True,
114
+ "retry_attempts": 3
115
+ },
116
+ "production": {
117
+ "url": "falkor://prod-server:6379",
118
+ "use_retry": True,
119
+ "retry_attempts": 5,
120
+ "socket_timeout": 10.0
121
+ }
122
+ }
123
+
124
+ # Switch to production configuration
125
+ settings_manager.active_key = "production"
126
+ db = get_falkordb()
127
+ ```
128
+
129
+ ### Runtime Overrides
130
+
131
+ ```python
132
+ from kiarina.lib.falkordb import get_falkordb
133
+
134
+ # Override settings at runtime
135
+ db = get_falkordb(
136
+ url="falkor://custom-server:6379",
137
+ use_retry=True
138
+ )
139
+ ```
140
+
141
+ ## Advanced Usage
142
+
143
+ ### Connection Caching
144
+
145
+ ```python
146
+ from kiarina.lib.falkordb import get_falkordb
147
+
148
+ # These will return the same cached connection
149
+ db1 = get_falkordb()
150
+ db2 = get_falkordb()
151
+ assert db1 is db2
152
+
153
+ # Use different cache keys for separate connections
154
+ db3 = get_falkordb(cache_key="secondary")
155
+ assert db1 is not db3
156
+ ```
157
+
158
+ ### Custom Configuration Keys
159
+
160
+ ```python
161
+ from kiarina.lib.falkordb import settings_manager, get_falkordb
162
+
163
+ # Configure multiple named configurations
164
+ settings_manager.user_config = {
165
+ "analytics": {
166
+ "url": "falkor://analytics-db:6379",
167
+ "socket_timeout": 30.0
168
+ },
169
+ "cache": {
170
+ "url": "falkor://cache-db:6379",
171
+ "socket_timeout": 5.0
172
+ }
173
+ }
174
+
175
+ # Use specific configurations
176
+ analytics_db = get_falkordb("analytics")
177
+ cache_db = get_falkordb("cache")
178
+ ```
179
+
180
+ ### Error Handling and Retries
181
+
182
+ ```python
183
+ from kiarina.lib.falkordb import get_falkordb
184
+
185
+ # Enable automatic retries for connection issues
186
+ db = get_falkordb(use_retry=True)
187
+
188
+ try:
189
+ graph = db.select_graph("mydata")
190
+ result = graph.query("MATCH (n) RETURN count(n)")
191
+ except Exception as e:
192
+ print(f"Query failed: {e}")
193
+ ```
194
+
195
+ ## Configuration Reference
196
+
197
+ | Setting | Environment Variable | Default | Description |
198
+ |---------|---------------------|---------|-------------|
199
+ | `url` | `KIARINA_LIB_FALKORDB_URL` | `"falkor://localhost:6379"` | FalkorDB connection URL |
200
+ | `use_retry` | `KIARINA_LIB_FALKORDB_USE_RETRY` | `false` | Enable automatic retries |
201
+ | `socket_timeout` | `KIARINA_LIB_FALKORDB_SOCKET_TIMEOUT` | `6.0` | Socket timeout in seconds |
202
+ | `socket_connect_timeout` | `KIARINA_LIB_FALKORDB_SOCKET_CONNECT_TIMEOUT` | `3.0` | Connection timeout in seconds |
203
+ | `health_check_interval` | `KIARINA_LIB_FALKORDB_HEALTH_CHECK_INTERVAL` | `60` | Health check interval in seconds |
204
+ | `retry_attempts` | `KIARINA_LIB_FALKORDB_RETRY_ATTEMPTS` | `3` | Number of retry attempts |
205
+ | `retry_delay` | `KIARINA_LIB_FALKORDB_RETRY_DELAY` | `1.0` | Delay between retries in seconds |
206
+
207
+ ## URL Formats
208
+
209
+ FalkorDB URLs support the following formats:
210
+
211
+ - `falkor://localhost:6379` - Basic connection
212
+ - `falkor://username:password@localhost:6379` - With authentication
213
+ - `falkors://localhost:6379` - SSL/TLS connection
214
+ - `falkors://username:password@localhost:6379` - SSL/TLS with authentication
215
+
216
+ ## Development
217
+
218
+ ### Prerequisites
219
+
220
+ - Python 3.12+
221
+ - Docker (for running FalkorDB in tests)
222
+
223
+ ### Setup
224
+
225
+ ```bash
226
+ # Clone the repository
227
+ git clone https://github.com/kiarina/kiarina-python.git
228
+ cd kiarina-python
229
+
230
+ # Setup development environment (installs tools, syncs dependencies, downloads test data)
231
+ mise run setup
232
+
233
+ # Start FalkorDB for testing
234
+ docker compose up -d falkordb
235
+ ```
236
+
237
+ ### Running Tests
238
+
239
+ ```bash
240
+ # Run format, lint, type checks and tests
241
+ mise run package kiarina-lib-falkordb
242
+
243
+ # Coverage report
244
+ mise run package:test kiarina-lib-falkordb --coverage
245
+
246
+ # Run specific tests
247
+ uv run --group test pytest packages/kiarina-lib-falkordb/tests/test_sync.py
248
+ uv run --group test pytest packages/kiarina-lib-falkordb/tests/test_async.py
249
+ ```
250
+
251
+ ## Dependencies
252
+
253
+ - [falkordb](https://github.com/kiarina/falkordb-py) - FalkorDB Python client (fork with redis-py 6.x support and async bug fixes)
254
+ - [pydantic-settings](https://docs.pydantic.dev/latest/concepts/pydantic_settings/) - Settings management
255
+ - [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) - Advanced settings management
256
+ - [redis](https://github.com/redis/redis-py) - Redis client (FalkorDB is Redis-compatible)
257
+
258
+ ### Note on FalkorDB Client
259
+
260
+ This library uses a [fork of the official FalkorDB Python client](https://github.com/kiarina/falkordb-py) instead of the [upstream version](https://github.com/FalkorDB/falkordb-py). The fork includes:
261
+
262
+ - **Redis-py 6.x compatibility**: Support for redis-py 6.4.0+ (upstream only supports 5.x)
263
+ - **Async client bug fixes**: Fixes for issues in the asynchronous client implementation
264
+ - **Enhanced stability**: Additional improvements for production use
265
+
266
+ The fork is based on the upstream `develop` branch and will be synchronized with upstream changes. Once these improvements are merged upstream, this library will migrate back to the official client.
267
+
268
+ ## License
269
+
270
+ This project is licensed under the MIT License - see the [LICENSE](../../LICENSE) file for details.
271
+
272
+ ## Contributing
273
+
274
+ This is a personal project, but contributions are welcome! Please feel free to submit issues or pull requests.
275
+
276
+ ## Related Projects
277
+
278
+ - [kiarina-python](https://github.com/kiarina/kiarina-python) - The main monorepo containing this package
279
+ - [FalkorDB](https://www.falkordb.com/) - The graph database this library connects to
280
+ - [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) - Configuration management library used by this package
@@ -0,0 +1,250 @@
1
+ # kiarina-lib-falkordb
2
+
3
+ A Python client library for [FalkorDB](https://falkordb.com/) with configuration management and connection pooling.
4
+
5
+ ## Features
6
+
7
+ - **Configuration Management**: Use `pydantic-settings-manager` for flexible configuration
8
+ - **Connection Pooling**: Automatic connection caching and reuse
9
+ - **Retry Support**: Built-in retry mechanism for connection failures
10
+ - **Sync & Async**: Support for both synchronous and asynchronous operations
11
+ - **Type Safety**: Full type hints and Pydantic validation
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pip install kiarina-lib-falkordb
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ### Basic Usage (Sync)
22
+
23
+ ```python
24
+ from kiarina.lib.falkordb import get_falkordb
25
+
26
+ # Get a FalkorDB client with default settings
27
+ db = get_falkordb()
28
+
29
+ # Select a graph and run a query
30
+ graph = db.select_graph("social")
31
+ result = graph.query("CREATE (p:Person {name: 'Alice', age: 30}) RETURN p")
32
+ print(result.result_set)
33
+ ```
34
+
35
+ ### Async Usage
36
+
37
+ ```python
38
+ from kiarina.lib.falkordb.asyncio import get_falkordb
39
+
40
+ async def main():
41
+ # Get an async FalkorDB client
42
+ db = get_falkordb()
43
+
44
+ # Select a graph and run a query
45
+ graph = db.select_graph("social")
46
+ result = await graph.query("CREATE (p:Person {name: 'Bob', age: 25}) RETURN p")
47
+ print(result.result_set)
48
+ ```
49
+
50
+ ## Configuration
51
+
52
+ This library uses [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) for flexible configuration management.
53
+
54
+ ### Environment Variables
55
+
56
+ Configure the FalkorDB connection using environment variables:
57
+
58
+ ```bash
59
+ # FalkorDB connection URL
60
+ export KIARINA_LIB_FALKORDB_URL="falkor://localhost:6379"
61
+
62
+ # Enable retry mechanism
63
+ export KIARINA_LIB_FALKORDB_USE_RETRY="true"
64
+
65
+ # Timeout settings
66
+ export KIARINA_LIB_FALKORDB_SOCKET_TIMEOUT="6.0"
67
+ export KIARINA_LIB_FALKORDB_SOCKET_CONNECT_TIMEOUT="3.0"
68
+
69
+ # Retry settings
70
+ export KIARINA_LIB_FALKORDB_RETRY_ATTEMPTS="3"
71
+ export KIARINA_LIB_FALKORDB_RETRY_DELAY="1.0"
72
+ ```
73
+
74
+ ### Programmatic Configuration
75
+
76
+ ```python
77
+ from kiarina.lib.falkordb import settings_manager
78
+
79
+ # Configure for multiple environments
80
+ settings_manager.user_config = {
81
+ "development": {
82
+ "url": "falkor://localhost:6379",
83
+ "use_retry": True,
84
+ "retry_attempts": 3
85
+ },
86
+ "production": {
87
+ "url": "falkor://prod-server:6379",
88
+ "use_retry": True,
89
+ "retry_attempts": 5,
90
+ "socket_timeout": 10.0
91
+ }
92
+ }
93
+
94
+ # Switch to production configuration
95
+ settings_manager.active_key = "production"
96
+ db = get_falkordb()
97
+ ```
98
+
99
+ ### Runtime Overrides
100
+
101
+ ```python
102
+ from kiarina.lib.falkordb import get_falkordb
103
+
104
+ # Override settings at runtime
105
+ db = get_falkordb(
106
+ url="falkor://custom-server:6379",
107
+ use_retry=True
108
+ )
109
+ ```
110
+
111
+ ## Advanced Usage
112
+
113
+ ### Connection Caching
114
+
115
+ ```python
116
+ from kiarina.lib.falkordb import get_falkordb
117
+
118
+ # These will return the same cached connection
119
+ db1 = get_falkordb()
120
+ db2 = get_falkordb()
121
+ assert db1 is db2
122
+
123
+ # Use different cache keys for separate connections
124
+ db3 = get_falkordb(cache_key="secondary")
125
+ assert db1 is not db3
126
+ ```
127
+
128
+ ### Custom Configuration Keys
129
+
130
+ ```python
131
+ from kiarina.lib.falkordb import settings_manager, get_falkordb
132
+
133
+ # Configure multiple named configurations
134
+ settings_manager.user_config = {
135
+ "analytics": {
136
+ "url": "falkor://analytics-db:6379",
137
+ "socket_timeout": 30.0
138
+ },
139
+ "cache": {
140
+ "url": "falkor://cache-db:6379",
141
+ "socket_timeout": 5.0
142
+ }
143
+ }
144
+
145
+ # Use specific configurations
146
+ analytics_db = get_falkordb("analytics")
147
+ cache_db = get_falkordb("cache")
148
+ ```
149
+
150
+ ### Error Handling and Retries
151
+
152
+ ```python
153
+ from kiarina.lib.falkordb import get_falkordb
154
+
155
+ # Enable automatic retries for connection issues
156
+ db = get_falkordb(use_retry=True)
157
+
158
+ try:
159
+ graph = db.select_graph("mydata")
160
+ result = graph.query("MATCH (n) RETURN count(n)")
161
+ except Exception as e:
162
+ print(f"Query failed: {e}")
163
+ ```
164
+
165
+ ## Configuration Reference
166
+
167
+ | Setting | Environment Variable | Default | Description |
168
+ |---------|---------------------|---------|-------------|
169
+ | `url` | `KIARINA_LIB_FALKORDB_URL` | `"falkor://localhost:6379"` | FalkorDB connection URL |
170
+ | `use_retry` | `KIARINA_LIB_FALKORDB_USE_RETRY` | `false` | Enable automatic retries |
171
+ | `socket_timeout` | `KIARINA_LIB_FALKORDB_SOCKET_TIMEOUT` | `6.0` | Socket timeout in seconds |
172
+ | `socket_connect_timeout` | `KIARINA_LIB_FALKORDB_SOCKET_CONNECT_TIMEOUT` | `3.0` | Connection timeout in seconds |
173
+ | `health_check_interval` | `KIARINA_LIB_FALKORDB_HEALTH_CHECK_INTERVAL` | `60` | Health check interval in seconds |
174
+ | `retry_attempts` | `KIARINA_LIB_FALKORDB_RETRY_ATTEMPTS` | `3` | Number of retry attempts |
175
+ | `retry_delay` | `KIARINA_LIB_FALKORDB_RETRY_DELAY` | `1.0` | Delay between retries in seconds |
176
+
177
+ ## URL Formats
178
+
179
+ FalkorDB URLs support the following formats:
180
+
181
+ - `falkor://localhost:6379` - Basic connection
182
+ - `falkor://username:password@localhost:6379` - With authentication
183
+ - `falkors://localhost:6379` - SSL/TLS connection
184
+ - `falkors://username:password@localhost:6379` - SSL/TLS with authentication
185
+
186
+ ## Development
187
+
188
+ ### Prerequisites
189
+
190
+ - Python 3.12+
191
+ - Docker (for running FalkorDB in tests)
192
+
193
+ ### Setup
194
+
195
+ ```bash
196
+ # Clone the repository
197
+ git clone https://github.com/kiarina/kiarina-python.git
198
+ cd kiarina-python
199
+
200
+ # Setup development environment (installs tools, syncs dependencies, downloads test data)
201
+ mise run setup
202
+
203
+ # Start FalkorDB for testing
204
+ docker compose up -d falkordb
205
+ ```
206
+
207
+ ### Running Tests
208
+
209
+ ```bash
210
+ # Run format, lint, type checks and tests
211
+ mise run package kiarina-lib-falkordb
212
+
213
+ # Coverage report
214
+ mise run package:test kiarina-lib-falkordb --coverage
215
+
216
+ # Run specific tests
217
+ uv run --group test pytest packages/kiarina-lib-falkordb/tests/test_sync.py
218
+ uv run --group test pytest packages/kiarina-lib-falkordb/tests/test_async.py
219
+ ```
220
+
221
+ ## Dependencies
222
+
223
+ - [falkordb](https://github.com/kiarina/falkordb-py) - FalkorDB Python client (fork with redis-py 6.x support and async bug fixes)
224
+ - [pydantic-settings](https://docs.pydantic.dev/latest/concepts/pydantic_settings/) - Settings management
225
+ - [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) - Advanced settings management
226
+ - [redis](https://github.com/redis/redis-py) - Redis client (FalkorDB is Redis-compatible)
227
+
228
+ ### Note on FalkorDB Client
229
+
230
+ This library uses a [fork of the official FalkorDB Python client](https://github.com/kiarina/falkordb-py) instead of the [upstream version](https://github.com/FalkorDB/falkordb-py). The fork includes:
231
+
232
+ - **Redis-py 6.x compatibility**: Support for redis-py 6.4.0+ (upstream only supports 5.x)
233
+ - **Async client bug fixes**: Fixes for issues in the asynchronous client implementation
234
+ - **Enhanced stability**: Additional improvements for production use
235
+
236
+ The fork is based on the upstream `develop` branch and will be synchronized with upstream changes. Once these improvements are merged upstream, this library will migrate back to the official client.
237
+
238
+ ## License
239
+
240
+ This project is licensed under the MIT License - see the [LICENSE](../../LICENSE) file for details.
241
+
242
+ ## Contributing
243
+
244
+ This is a personal project, but contributions are welcome! Please feel free to submit issues or pull requests.
245
+
246
+ ## Related Projects
247
+
248
+ - [kiarina-python](https://github.com/kiarina/kiarina-python) - The main monorepo containing this package
249
+ - [FalkorDB](https://www.falkordb.com/) - The graph database this library connects to
250
+ - [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) - Configuration management library used by this package
@@ -0,0 +1,49 @@
1
+ [project]
2
+ name = "kiarina-lib-falkordb"
3
+ version = "1.0.0"
4
+ description = "FalkorDB client library for kiarina namespace"
5
+ readme = "README.md"
6
+ license = { text = "MIT" }
7
+ authors = [
8
+ { name = "kiarina", email = "kiarinadawa@gmail.com" }
9
+ ]
10
+ maintainers = [
11
+ { name = "kiarina", email = "kiarinadawa@gmail.com" }
12
+ ]
13
+ keywords = ["falkordb", "graph", "redis", "pydantic", "settings", "database", "client"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Topic :: Database",
23
+ "Topic :: Software Development :: Libraries :: Python Modules",
24
+ "Typing :: Typed",
25
+ ]
26
+ requires-python = ">=3.12"
27
+ dependencies = [
28
+ "falkordb",
29
+ "pydantic-settings>=2.10.1",
30
+ "pydantic-settings-manager>=2.1.0",
31
+ "redis>=6.4.0",
32
+ ]
33
+
34
+ [tool.uv.sources]
35
+ falkordb = { git = "https://github.com/kiarina/falkordb-py.git", rev = "develop" }
36
+
37
+ [project.urls]
38
+ Homepage = "https://github.com/kiarina/kiarina-python"
39
+ Repository = "https://github.com/kiarina/kiarina-python"
40
+ Issues = "https://github.com/kiarina/kiarina-python/issues"
41
+ Changelog = "https://github.com/kiarina/kiarina-python/blob/main/packages/kiarina-lib-falkordb/CHANGELOG.md"
42
+ Documentation = "https://github.com/kiarina/kiarina-python/tree/main/packages/kiarina-lib-falkordb#readme"
43
+
44
+ [build-system]
45
+ requires = ["hatchling"]
46
+ build-backend = "hatchling.build"
47
+
48
+ [tool.hatch.build.targets.wheel]
49
+ packages = ["src/kiarina"]
@@ -0,0 +1,27 @@
1
+ import logging
2
+ from importlib import import_module
3
+ from importlib.metadata import version
4
+ from typing import TYPE_CHECKING
5
+
6
+ if TYPE_CHECKING:
7
+ from ._sync.registry import get_falkordb
8
+ from .settings import settings_manager
9
+
10
+ __version__ = version("kiarina-lib-falkordb")
11
+
12
+ __all__ = ["get_falkordb", "settings_manager"]
13
+
14
+ logging.getLogger(__name__).addHandler(logging.NullHandler())
15
+
16
+
17
+ def __getattr__(name: str) -> object:
18
+ if name not in __all__:
19
+ raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
20
+
21
+ module_map = {
22
+ "get_falkordb": "._sync.registry",
23
+ "settings_manager": ".settings",
24
+ }
25
+
26
+ globals()[name] = getattr(import_module(module_map[name], __name__), name)
27
+ return globals()[name]
@@ -0,0 +1,39 @@
1
+ from typing import Any
2
+
3
+ from falkordb.asyncio import FalkorDB # type: ignore
4
+
5
+ from .._core.registry import get_falkordb as _get_falkordb
6
+
7
+
8
+ def get_falkordb(
9
+ config_key: str | None = None,
10
+ *,
11
+ cache_key: str | None = None,
12
+ use_retry: bool | None = None,
13
+ url: str | None = None,
14
+ **kwargs: Any,
15
+ ) -> FalkorDB:
16
+ """
17
+ Get a FalkorDB client (async version - currently uses sync implementation).
18
+
19
+ Note: FalkorDB doesn't have native async support yet, so this currently
20
+ returns the same sync client. This is prepared for future async support.
21
+
22
+ Args:
23
+ config_key (str | None): The configuration key for the FalkorDB client.
24
+ cache_key (str | None): The cache key for the FalkorDB client.
25
+ use_retry (bool | None): Whether to use retry for the FalkorDB client.
26
+ url (str | None): The FalkorDB URL.
27
+ **kwargs: Additional keyword arguments for the FalkorDB client.
28
+
29
+ Returns:
30
+ FalkorDB: The FalkorDB client.
31
+ """
32
+ return _get_falkordb(
33
+ "async",
34
+ config_key,
35
+ cache_key=cache_key,
36
+ use_retry=use_retry,
37
+ url=url,
38
+ **kwargs,
39
+ )
@@ -0,0 +1,103 @@
1
+ from typing import Any, Literal, overload
2
+
3
+ import falkordb # type: ignore
4
+ import falkordb.asyncio # type: ignore
5
+ import redis
6
+ import redis.asyncio
7
+ from redis.backoff import ExponentialBackoff
8
+ from redis.retry import Retry
9
+
10
+ from ..settings import settings_manager
11
+
12
+ _sync_cache: dict[str, falkordb.FalkorDB] = {}
13
+ """
14
+ Sync FalkorDB clients cache
15
+ """
16
+
17
+ _async_cache: dict[str, falkordb.asyncio.FalkorDB] = {}
18
+ """
19
+ Async FalkorDB clients cache
20
+ """
21
+
22
+
23
+ @overload
24
+ def get_falkordb(
25
+ mode: Literal["sync"],
26
+ config_key: str | None = None,
27
+ *,
28
+ cache_key: str | None = None,
29
+ use_retry: bool | None = None,
30
+ url: str | None = None,
31
+ **kwargs: Any,
32
+ ) -> falkordb.FalkorDB: ...
33
+
34
+
35
+ @overload
36
+ def get_falkordb(
37
+ mode: Literal["async"],
38
+ config_key: str | None = None,
39
+ *,
40
+ cache_key: str | None = None,
41
+ use_retry: bool | None = None,
42
+ url: str | None = None,
43
+ **kwargs: Any,
44
+ ) -> falkordb.asyncio.FalkorDB: ...
45
+
46
+
47
+ def get_falkordb(
48
+ mode: Literal["sync", "async"],
49
+ config_key: str | None = None,
50
+ *,
51
+ cache_key: str | None = None,
52
+ use_retry: bool | None = None,
53
+ url: str | None = None,
54
+ **kwargs: Any,
55
+ ) -> falkordb.FalkorDB | falkordb.asyncio.FalkorDB:
56
+ """
57
+ Get a FalkorDB client with shared logic.
58
+ """
59
+ settings = settings_manager.get_settings_by_key(config_key)
60
+
61
+ if url is None:
62
+ url = settings.url
63
+
64
+ if use_retry is None:
65
+ use_retry = settings.use_retry
66
+
67
+ params = {**settings.initialize_params, **kwargs}
68
+
69
+ if use_retry:
70
+ params.update(
71
+ {
72
+ "socket_timeout": settings.socket_timeout,
73
+ "socket_connect_timeout": settings.socket_connect_timeout,
74
+ "health_check_interval": settings.health_check_interval,
75
+ "retry": Retry(
76
+ ExponentialBackoff(cap=settings.retry_delay),
77
+ settings.retry_attempts,
78
+ ),
79
+ }
80
+ )
81
+
82
+ if mode == "sync":
83
+ params["retry_on_error"] = [redis.ConnectionError, redis.TimeoutError]
84
+ else:
85
+ params["retry_on_error"] = [
86
+ redis.asyncio.ConnectionError,
87
+ redis.asyncio.TimeoutError,
88
+ ]
89
+
90
+ if cache_key is None:
91
+ cache_key = url
92
+
93
+ if mode == "sync":
94
+ if cache_key not in _sync_cache:
95
+ _sync_cache[cache_key] = falkordb.FalkorDB.from_url(url, **params)
96
+
97
+ return _sync_cache[cache_key]
98
+
99
+ else:
100
+ if cache_key not in _async_cache:
101
+ _async_cache[cache_key] = falkordb.asyncio.FalkorDB.from_url(url, **params)
102
+
103
+ return _async_cache[cache_key]
@@ -0,0 +1,36 @@
1
+ from typing import Any
2
+
3
+ from falkordb import FalkorDB # type: ignore
4
+
5
+ from .._core.registry import get_falkordb as _get_falkordb
6
+
7
+
8
+ def get_falkordb(
9
+ config_key: str | None = None,
10
+ *,
11
+ cache_key: str | None = None,
12
+ use_retry: bool | None = None,
13
+ url: str | None = None,
14
+ **kwargs: Any,
15
+ ) -> FalkorDB:
16
+ """
17
+ Get a FalkorDB client.
18
+
19
+ Args:
20
+ config_key (str | None): The configuration key for the FalkorDB client.
21
+ cache_key (str | None): The cache key for the FalkorDB client.
22
+ use_retry (bool | None): Whether to use retry for the FalkorDB client.
23
+ url (str | None): The FalkorDB URL.
24
+ **kwargs: Additional keyword arguments for the FalkorDB client.
25
+
26
+ Returns:
27
+ FalkorDB: The FalkorDB client.
28
+ """
29
+ return _get_falkordb(
30
+ "sync",
31
+ config_key,
32
+ cache_key=cache_key,
33
+ use_retry=use_retry,
34
+ url=url,
35
+ **kwargs,
36
+ )
@@ -0,0 +1,25 @@
1
+ import logging
2
+ from importlib import import_module
3
+ from typing import TYPE_CHECKING
4
+
5
+ if TYPE_CHECKING:
6
+ from ._async.registry import get_falkordb
7
+ from .settings import settings_manager
8
+
9
+ __all__ = ["get_falkordb", "settings_manager"]
10
+
11
+ logging.getLogger(__name__).addHandler(logging.NullHandler())
12
+
13
+
14
+ def __getattr__(name: str) -> object:
15
+ if name not in __all__:
16
+ raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
17
+
18
+ module_map = {
19
+ "get_falkordb": "._async.registry",
20
+ "settings_manager": ".settings",
21
+ }
22
+
23
+ parent = __name__.rsplit(".", 1)[0]
24
+ globals()[name] = getattr(import_module(module_map[name], parent), name)
25
+ return globals()[name]
@@ -0,0 +1,70 @@
1
+ from typing import Any
2
+
3
+ from pydantic import Field
4
+ from pydantic_settings import BaseSettings, SettingsConfigDict
5
+ from pydantic_settings_manager import SettingsManager
6
+
7
+
8
+ class FalkorDBSettings(BaseSettings):
9
+ """
10
+ FalkorDB Settings
11
+ """
12
+
13
+ model_config = SettingsConfigDict(env_prefix="KIARINA_LIB_FALKORDB_")
14
+
15
+ url: str = "falkor://localhost:6379"
16
+ """
17
+ FalkorDB URL
18
+
19
+ Example:
20
+ - falkor://[[username]:[password]]@localhost:6379
21
+ - falkors://[[username]:[password]]@localhost:6379
22
+ """
23
+
24
+ initialize_params: dict[str, Any] = Field(default_factory=dict)
25
+ """
26
+ Additional parameters to initialize the FalkorDB client.
27
+ """
28
+
29
+ use_retry: bool = False
30
+ """
31
+ Whether to enable automatic retries
32
+
33
+ When enabled, it is configured to retry upon occurrence of
34
+ redis.ConnectionError or redis.TimeoutError.
35
+ """
36
+
37
+ socket_timeout: float = 6.0
38
+ """
39
+ Socket timeout in seconds
40
+
41
+ After sending a command, if this time is exceeded, a redis.TimeoutError will be raised.
42
+ """
43
+
44
+ socket_connect_timeout: float = 3.0
45
+ """
46
+ Socket connection timeout in seconds
47
+
48
+ If this time is exceeded when establishing a new connection, a redis.ConnectionError will occur.
49
+ """
50
+
51
+ health_check_interval: int = 60
52
+ """
53
+ Health check interval in seconds
54
+
55
+ When acquiring a connection from the pool,
56
+ if the time since last use has elapsed, execute a PING to verify the connection status.
57
+ """
58
+
59
+ retry_attempts: int = 3
60
+ """
61
+ Number of retry attempts
62
+ """
63
+
64
+ retry_delay: float = 1.0
65
+ """
66
+ Delay between retry attempts in seconds
67
+ """
68
+
69
+
70
+ settings_manager = SettingsManager(FalkorDBSettings, multi=True)
File without changes
File without changes
@@ -0,0 +1,17 @@
1
+ from kiarina.lib.falkordb.asyncio import get_falkordb
2
+
3
+
4
+ async def test_get_falkordb() -> None:
5
+ # Check if it is cached
6
+ db1 = get_falkordb(use_retry=True)
7
+ db2 = get_falkordb()
8
+ assert db1 is db2
9
+
10
+ # Verify that changing the cache key allows retrieval of a different instance
11
+ db3 = get_falkordb(cache_key="other")
12
+ assert db1 is not db3
13
+
14
+ # Test basic query execution
15
+ g = db1.select_graph("test")
16
+ nodes = (await g.query("CREATE (n:TestNode {name: 'Test'}) RETURN n")).result_set
17
+ assert len(nodes) == 1
@@ -0,0 +1,17 @@
1
+ from kiarina.lib.falkordb import get_falkordb
2
+
3
+
4
+ def test_get_falkordb() -> None:
5
+ # Check if it is cached
6
+ db1 = get_falkordb(use_retry=True)
7
+ db2 = get_falkordb()
8
+ assert db1 is db2
9
+
10
+ # Verify that changing the cache key allows retrieval of a different instance
11
+ db3 = get_falkordb(cache_key="other")
12
+ assert db1 is not db3
13
+
14
+ # Test basic query execution
15
+ g = db1.select_graph("test")
16
+ nodes = g.query("CREATE (n:TestNode {name: 'Test'}) RETURN n").result_set
17
+ assert len(nodes) == 1