kiarina-lib-falkordb 1.9.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,35 @@
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
+ # OS
23
+ .DS_Store
24
+
25
+ # Project specific
26
+ *.log
27
+ tmp/
28
+ packages/*/test_settings.yaml
29
+
30
+ # Test data
31
+ tests/data/large/
32
+
33
+ # mise tasks (always include)
34
+ !mise-tasks/
35
+ !mise-tasks/**
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,8 @@
1
+ {
2
+ "python.testing.pytestArgs": [
3
+ "tests"
4
+ ],
5
+ "python.testing.unittestEnabled": false,
6
+ "python.testing.pytestEnabled": true,
7
+ "python.envFile": "${workspaceFolder}/.env"
8
+ }
@@ -0,0 +1,106 @@
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.9.0] - 2025-11-26
11
+
12
+ ### Changed
13
+ - No changes
14
+
15
+ ## [1.8.0] - 2025-10-24
16
+
17
+ ### Changed
18
+ - Updated `kiarina-falkordb` dependency from `>=1.2.0` to `>=1.3.0`
19
+
20
+ ## [1.7.0] - 2025-10-21
21
+
22
+ ### Changed
23
+ - No changes
24
+
25
+ ## [1.6.3] - 2025-10-13
26
+
27
+ ### Changed
28
+ - Updated `pydantic-settings-manager` dependency from `>=2.1.0` to `>=2.3.0`
29
+
30
+ ## [1.6.2] - 2025-10-10
31
+
32
+ ### Changed
33
+ - No changes
34
+
35
+ ## [1.6.1] - 2025-10-10
36
+
37
+ ### Changed
38
+ - No changes
39
+
40
+ ## [1.6.0] - 2025-10-10
41
+
42
+ ### Changed
43
+ - No changes
44
+
45
+ ## [1.5.0] - 2025-10-10
46
+
47
+ ### Changed
48
+ - No changes
49
+
50
+ ## [1.4.0] - 2025-10-09
51
+
52
+ ### Changed
53
+ - **BREAKING**: Changed `url` field to use `SecretStr` for enhanced security
54
+ - FalkorDB connection URLs (which may contain passwords) are now masked in string representations and logs
55
+ - Prevents accidental exposure of credentials in debug output
56
+ - Access URL value via `.get_secret_value()` method when needed
57
+ - Internal usage automatically handles secret extraction
58
+
59
+ ### Security
60
+ - **Enhanced credential protection**: FalkorDB URLs with embedded credentials are now protected from accidental exposure
61
+ - URLs are displayed as `**********` in logs and string representations
62
+ - Follows the project-wide security policy for sensitive data
63
+
64
+ ## [1.3.0] - 2025-10-05
65
+
66
+ ### Changed
67
+ - No changes
68
+
69
+ ## [1.2.0] - 2025-09-25
70
+
71
+ ### Changed
72
+ - No changes
73
+
74
+ ## [1.1.1] - 2025-01-15
75
+
76
+ ### Changed
77
+ - Switched from `falkordb` to `kiarina-falkordb` dependency for better compatibility and maintenance
78
+
79
+ ## [1.1.0] - 2025-09-11
80
+
81
+ ### Changed
82
+ - No changes
83
+
84
+ ## [1.0.1] - 2025-09-11
85
+
86
+ ### Changed
87
+ - No changes - version bump for consistency with other packages
88
+
89
+ ## [1.0.0] - 2025-09-09
90
+
91
+ ### Added
92
+ - Initial release of kiarina-lib-falkordb
93
+ - FalkorDB client with configuration management using pydantic-settings-manager
94
+ - Connection pooling and caching
95
+ - Retry mechanism for connection failures
96
+ - Support for both sync and async operations (async prepared for future FalkorDB support)
97
+ - Type safety with full type hints and Pydantic validation
98
+ - Environment variable configuration support
99
+ - Runtime configuration overrides
100
+ - Multiple named configurations support
101
+
102
+ ### Dependencies
103
+ - falkordb (from kiarina/falkordb-py fork with redis6 support)
104
+ - pydantic-settings>=2.10.1
105
+ - pydantic-settings-manager>=2.1.0
106
+ - redis>=6.4.0
@@ -0,0 +1,279 @@
1
+ Metadata-Version: 2.4
2
+ Name: kiarina-lib-falkordb
3
+ Version: 1.9.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-Expression: MIT
13
+ Keywords: client,database,falkordb,graph,pydantic,redis,settings
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Database
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.12
24
+ Requires-Dist: kiarina-falkordb>=1.3.0
25
+ Requires-Dist: pydantic-settings-manager>=2.3.0
26
+ Requires-Dist: pydantic-settings>=2.10.1
27
+ Requires-Dist: redis>=6.4.0
28
+ Description-Content-Type: text/markdown
29
+
30
+ # kiarina-lib-falkordb
31
+
32
+ A Python client library for [FalkorDB](https://falkordb.com/) with configuration management and connection pooling.
33
+
34
+ ## Features
35
+
36
+ - **Configuration Management**: Use `pydantic-settings-manager` for flexible configuration
37
+ - **Connection Pooling**: Automatic connection caching and reuse
38
+ - **Retry Support**: Built-in retry mechanism for connection failures
39
+ - **Sync & Async**: Support for both synchronous and asynchronous operations
40
+ - **Type Safety**: Full type hints and Pydantic validation
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ pip install kiarina-lib-falkordb
46
+ ```
47
+
48
+ ## Quick Start
49
+
50
+ ### Basic Usage (Sync)
51
+
52
+ ```python
53
+ from kiarina.lib.falkordb import get_falkordb
54
+
55
+ # Get a FalkorDB client with default settings
56
+ db = get_falkordb()
57
+
58
+ # Select a graph and run a query
59
+ graph = db.select_graph("social")
60
+ result = graph.query("CREATE (p:Person {name: 'Alice', age: 30}) RETURN p")
61
+ print(result.result_set)
62
+ ```
63
+
64
+ ### Async Usage
65
+
66
+ ```python
67
+ from kiarina.lib.falkordb.asyncio import get_falkordb
68
+
69
+ async def main():
70
+ # Get an async FalkorDB client
71
+ db = get_falkordb()
72
+
73
+ # Select a graph and run a query
74
+ graph = db.select_graph("social")
75
+ result = await graph.query("CREATE (p:Person {name: 'Bob', age: 25}) RETURN p")
76
+ print(result.result_set)
77
+ ```
78
+
79
+ ## Configuration
80
+
81
+ This library uses [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) for flexible configuration management.
82
+
83
+ ### Environment Variables
84
+
85
+ Configure the FalkorDB connection using environment variables:
86
+
87
+ ```bash
88
+ # FalkorDB connection URL
89
+ export KIARINA_LIB_FALKORDB_URL="falkor://localhost:6379"
90
+
91
+ # Enable retry mechanism
92
+ export KIARINA_LIB_FALKORDB_USE_RETRY="true"
93
+
94
+ # Timeout settings
95
+ export KIARINA_LIB_FALKORDB_SOCKET_TIMEOUT="6.0"
96
+ export KIARINA_LIB_FALKORDB_SOCKET_CONNECT_TIMEOUT="3.0"
97
+
98
+ # Retry settings
99
+ export KIARINA_LIB_FALKORDB_RETRY_ATTEMPTS="3"
100
+ export KIARINA_LIB_FALKORDB_RETRY_DELAY="1.0"
101
+ ```
102
+
103
+ ### Programmatic Configuration
104
+
105
+ ```python
106
+ from kiarina.lib.falkordb import settings_manager
107
+
108
+ # Configure for multiple environments
109
+ settings_manager.user_config = {
110
+ "development": {
111
+ "url": "falkor://localhost:6379",
112
+ "use_retry": True,
113
+ "retry_attempts": 3
114
+ },
115
+ "production": {
116
+ "url": "falkor://prod-server:6379",
117
+ "use_retry": True,
118
+ "retry_attempts": 5,
119
+ "socket_timeout": 10.0
120
+ }
121
+ }
122
+
123
+ # Switch to production configuration
124
+ settings_manager.active_key = "production"
125
+ db = get_falkordb()
126
+ ```
127
+
128
+ ### Runtime Overrides
129
+
130
+ ```python
131
+ from kiarina.lib.falkordb import get_falkordb
132
+
133
+ # Override settings at runtime
134
+ db = get_falkordb(
135
+ url="falkor://custom-server:6379",
136
+ use_retry=True
137
+ )
138
+ ```
139
+
140
+ ## Advanced Usage
141
+
142
+ ### Connection Caching
143
+
144
+ ```python
145
+ from kiarina.lib.falkordb import get_falkordb
146
+
147
+ # These will return the same cached connection
148
+ db1 = get_falkordb()
149
+ db2 = get_falkordb()
150
+ assert db1 is db2
151
+
152
+ # Use different cache keys for separate connections
153
+ db3 = get_falkordb(cache_key="secondary")
154
+ assert db1 is not db3
155
+ ```
156
+
157
+ ### Custom Configuration Keys
158
+
159
+ ```python
160
+ from kiarina.lib.falkordb import settings_manager, get_falkordb
161
+
162
+ # Configure multiple named configurations
163
+ settings_manager.user_config = {
164
+ "analytics": {
165
+ "url": "falkor://analytics-db:6379",
166
+ "socket_timeout": 30.0
167
+ },
168
+ "cache": {
169
+ "url": "falkor://cache-db:6379",
170
+ "socket_timeout": 5.0
171
+ }
172
+ }
173
+
174
+ # Use specific configurations
175
+ analytics_db = get_falkordb("analytics")
176
+ cache_db = get_falkordb("cache")
177
+ ```
178
+
179
+ ### Error Handling and Retries
180
+
181
+ ```python
182
+ from kiarina.lib.falkordb import get_falkordb
183
+
184
+ # Enable automatic retries for connection issues
185
+ db = get_falkordb(use_retry=True)
186
+
187
+ try:
188
+ graph = db.select_graph("mydata")
189
+ result = graph.query("MATCH (n) RETURN count(n)")
190
+ except Exception as e:
191
+ print(f"Query failed: {e}")
192
+ ```
193
+
194
+ ## Configuration Reference
195
+
196
+ | Setting | Environment Variable | Default | Description |
197
+ |---------|---------------------|---------|-------------|
198
+ | `url` | `KIARINA_LIB_FALKORDB_URL` | `"falkor://localhost:6379"` | FalkorDB connection URL |
199
+ | `use_retry` | `KIARINA_LIB_FALKORDB_USE_RETRY` | `false` | Enable automatic retries |
200
+ | `socket_timeout` | `KIARINA_LIB_FALKORDB_SOCKET_TIMEOUT` | `6.0` | Socket timeout in seconds |
201
+ | `socket_connect_timeout` | `KIARINA_LIB_FALKORDB_SOCKET_CONNECT_TIMEOUT` | `3.0` | Connection timeout in seconds |
202
+ | `health_check_interval` | `KIARINA_LIB_FALKORDB_HEALTH_CHECK_INTERVAL` | `60` | Health check interval in seconds |
203
+ | `retry_attempts` | `KIARINA_LIB_FALKORDB_RETRY_ATTEMPTS` | `3` | Number of retry attempts |
204
+ | `retry_delay` | `KIARINA_LIB_FALKORDB_RETRY_DELAY` | `1.0` | Delay between retries in seconds |
205
+
206
+ ## URL Formats
207
+
208
+ FalkorDB URLs support the following formats:
209
+
210
+ - `falkor://localhost:6379` - Basic connection
211
+ - `falkor://username:password@localhost:6379` - With authentication
212
+ - `falkors://localhost:6379` - SSL/TLS connection
213
+ - `falkors://username:password@localhost:6379` - SSL/TLS with authentication
214
+
215
+ ## Development
216
+
217
+ ### Prerequisites
218
+
219
+ - Python 3.12+
220
+ - Docker (for running FalkorDB in tests)
221
+
222
+ ### Setup
223
+
224
+ ```bash
225
+ # Clone the repository
226
+ git clone https://github.com/kiarina/kiarina-python.git
227
+ cd kiarina-python
228
+
229
+ # Setup development environment (installs tools, syncs dependencies, downloads test data)
230
+ mise run setup
231
+
232
+ # Start FalkorDB for testing
233
+ docker compose up -d falkordb
234
+ ```
235
+
236
+ ### Running Tests
237
+
238
+ ```bash
239
+ # Run format, lint, type checks and tests
240
+ mise run package kiarina-lib-falkordb
241
+
242
+ # Coverage report
243
+ mise run package:test kiarina-lib-falkordb --coverage
244
+
245
+ # Run specific tests
246
+ uv run --group test pytest packages/kiarina-lib-falkordb/tests/test_sync.py
247
+ uv run --group test pytest packages/kiarina-lib-falkordb/tests/test_async.py
248
+ ```
249
+
250
+ ## Dependencies
251
+
252
+ - [falkordb](https://github.com/kiarina/falkordb-py) - FalkorDB Python client (fork with redis-py 6.x support and async bug fixes)
253
+ - [pydantic-settings](https://docs.pydantic.dev/latest/concepts/pydantic_settings/) - Settings management
254
+ - [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) - Advanced settings management
255
+ - [redis](https://github.com/redis/redis-py) - Redis client (FalkorDB is Redis-compatible)
256
+
257
+ ### Note on FalkorDB Client
258
+
259
+ 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:
260
+
261
+ - **Redis-py 6.x compatibility**: Support for redis-py 6.4.0+ (upstream only supports 5.x)
262
+ - **Async client bug fixes**: Fixes for issues in the asynchronous client implementation
263
+ - **Enhanced stability**: Additional improvements for production use
264
+
265
+ 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.
266
+
267
+ ## License
268
+
269
+ This project is licensed under the MIT License - see the [LICENSE](../../LICENSE) file for details.
270
+
271
+ ## Contributing
272
+
273
+ This is a personal project, but contributions are welcome! Please feel free to submit issues or pull requests.
274
+
275
+ ## Related Projects
276
+
277
+ - [kiarina-python](https://github.com/kiarina/kiarina-python) - The main monorepo containing this package
278
+ - [FalkorDB](https://www.falkordb.com/) - The graph database this library connects to
279
+ - [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,45 @@
1
+ [project]
2
+ name = "kiarina-lib-falkordb"
3
+ version = "1.9.0"
4
+ description = "FalkorDB client library for kiarina namespace"
5
+ readme = "README.md"
6
+ license = "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
+ "Operating System :: OS Independent",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Topic :: Database",
22
+ "Topic :: Software Development :: Libraries :: Python Modules",
23
+ "Typing :: Typed",
24
+ ]
25
+ requires-python = ">=3.12"
26
+ dependencies = [
27
+ "kiarina-falkordb>=1.3.0",
28
+ "pydantic-settings>=2.10.1",
29
+ "pydantic-settings-manager>=2.3.0",
30
+ "redis>=6.4.0",
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/kiarina/kiarina-python"
35
+ Repository = "https://github.com/kiarina/kiarina-python"
36
+ Issues = "https://github.com/kiarina/kiarina-python/issues"
37
+ Changelog = "https://github.com/kiarina/kiarina-python/blob/main/packages/kiarina-lib-falkordb/CHANGELOG.md"
38
+ Documentation = "https://github.com/kiarina/kiarina-python/tree/main/packages/kiarina-lib-falkordb#readme"
39
+
40
+ [build-system]
41
+ requires = ["hatchling"]
42
+ build-backend = "hatchling.build"
43
+
44
+ [tool.hatch.build.targets.wheel]
45
+ 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(config_key)
60
+
61
+ if url is None:
62
+ url = settings.url.get_secret_value()
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,72 @@
1
+ from typing import Any
2
+
3
+ from pydantic import Field, SecretStr
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: SecretStr = SecretStr("falkor://localhost:6379")
16
+ """
17
+ FalkorDB URL
18
+
19
+ Example:
20
+ - falkor://[[username]:[password]]@localhost:6379
21
+ - falkors://[[username]:[password]]@localhost:6379
22
+
23
+ Note: This field uses SecretStr to prevent accidental exposure of credentials in logs.
24
+ """
25
+
26
+ initialize_params: dict[str, Any] = Field(default_factory=dict)
27
+ """
28
+ Additional parameters to initialize the FalkorDB client.
29
+ """
30
+
31
+ use_retry: bool = False
32
+ """
33
+ Whether to enable automatic retries
34
+
35
+ When enabled, it is configured to retry upon occurrence of
36
+ redis.ConnectionError or redis.TimeoutError.
37
+ """
38
+
39
+ socket_timeout: float = 6.0
40
+ """
41
+ Socket timeout in seconds
42
+
43
+ After sending a command, if this time is exceeded, a redis.TimeoutError will be raised.
44
+ """
45
+
46
+ socket_connect_timeout: float = 3.0
47
+ """
48
+ Socket connection timeout in seconds
49
+
50
+ If this time is exceeded when establishing a new connection, a redis.ConnectionError will occur.
51
+ """
52
+
53
+ health_check_interval: int = 60
54
+ """
55
+ Health check interval in seconds
56
+
57
+ When acquiring a connection from the pool,
58
+ if the time since last use has elapsed, execute a PING to verify the connection status.
59
+ """
60
+
61
+ retry_attempts: int = 3
62
+ """
63
+ Number of retry attempts
64
+ """
65
+
66
+ retry_delay: float = 1.0
67
+ """
68
+ Delay between retry attempts in seconds
69
+ """
70
+
71
+
72
+ 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