fdb-record-layer 0.1.0b1__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 (94) hide show
  1. fdb_record_layer-0.1.0b1/LICENSE +190 -0
  2. fdb_record_layer-0.1.0b1/PKG-INFO +255 -0
  3. fdb_record_layer-0.1.0b1/README.md +218 -0
  4. fdb_record_layer-0.1.0b1/fdb_record_layer/__init__.py +295 -0
  5. fdb_record_layer-0.1.0b1/fdb_record_layer/core/__init__.py +60 -0
  6. fdb_record_layer-0.1.0b1/fdb_record_layer/core/context.py +367 -0
  7. fdb_record_layer-0.1.0b1/fdb_record_layer/core/exceptions.py +140 -0
  8. fdb_record_layer-0.1.0b1/fdb_record_layer/core/record.py +123 -0
  9. fdb_record_layer-0.1.0b1/fdb_record_layer/core/store.py +1029 -0
  10. fdb_record_layer-0.1.0b1/fdb_record_layer/cursors/__init__.py +0 -0
  11. fdb_record_layer-0.1.0b1/fdb_record_layer/cursors/base.py +366 -0
  12. fdb_record_layer-0.1.0b1/fdb_record_layer/cursors/result.py +187 -0
  13. fdb_record_layer-0.1.0b1/fdb_record_layer/expressions/__init__.py +0 -0
  14. fdb_record_layer-0.1.0b1/fdb_record_layer/expressions/base.py +158 -0
  15. fdb_record_layer-0.1.0b1/fdb_record_layer/expressions/concat.py +124 -0
  16. fdb_record_layer-0.1.0b1/fdb_record_layer/expressions/field.py +127 -0
  17. fdb_record_layer-0.1.0b1/fdb_record_layer/expressions/nest.py +112 -0
  18. fdb_record_layer-0.1.0b1/fdb_record_layer/expressions/record_type.py +58 -0
  19. fdb_record_layer-0.1.0b1/fdb_record_layer/indexes/__init__.py +66 -0
  20. fdb_record_layer-0.1.0b1/fdb_record_layer/indexes/builder.py +463 -0
  21. fdb_record_layer-0.1.0b1/fdb_record_layer/indexes/count_index.py +470 -0
  22. fdb_record_layer-0.1.0b1/fdb_record_layer/indexes/maintainer.py +240 -0
  23. fdb_record_layer-0.1.0b1/fdb_record_layer/indexes/rank_index.py +434 -0
  24. fdb_record_layer-0.1.0b1/fdb_record_layer/indexes/registry.py +171 -0
  25. fdb_record_layer-0.1.0b1/fdb_record_layer/indexes/text_index.py +213 -0
  26. fdb_record_layer-0.1.0b1/fdb_record_layer/indexes/value_index.py +189 -0
  27. fdb_record_layer-0.1.0b1/fdb_record_layer/metadata/__init__.py +57 -0
  28. fdb_record_layer-0.1.0b1/fdb_record_layer/metadata/evolution.py +515 -0
  29. fdb_record_layer-0.1.0b1/fdb_record_layer/metadata/index.py +153 -0
  30. fdb_record_layer-0.1.0b1/fdb_record_layer/metadata/meta_data_builder.py +334 -0
  31. fdb_record_layer-0.1.0b1/fdb_record_layer/metadata/meta_data_store.py +416 -0
  32. fdb_record_layer-0.1.0b1/fdb_record_layer/metadata/record_metadata.py +172 -0
  33. fdb_record_layer-0.1.0b1/fdb_record_layer/planner/__init__.py +46 -0
  34. fdb_record_layer-0.1.0b1/fdb_record_layer/planner/cascades/__init__.py +128 -0
  35. fdb_record_layer-0.1.0b1/fdb_record_layer/planner/cascades/cost_model.py +413 -0
  36. fdb_record_layer-0.1.0b1/fdb_record_layer/planner/cascades/expressions.py +578 -0
  37. fdb_record_layer-0.1.0b1/fdb_record_layer/planner/cascades/memo.py +486 -0
  38. fdb_record_layer-0.1.0b1/fdb_record_layer/planner/cascades/planner.py +531 -0
  39. fdb_record_layer-0.1.0b1/fdb_record_layer/planner/cascades/rule.py +654 -0
  40. fdb_record_layer-0.1.0b1/fdb_record_layer/planner/heuristic.py +511 -0
  41. fdb_record_layer-0.1.0b1/fdb_record_layer/planner/scan_comparisons.py +325 -0
  42. fdb_record_layer-0.1.0b1/fdb_record_layer/plans/__init__.py +54 -0
  43. fdb_record_layer-0.1.0b1/fdb_record_layer/plans/base.py +242 -0
  44. fdb_record_layer-0.1.0b1/fdb_record_layer/plans/filter_plan.py +292 -0
  45. fdb_record_layer-0.1.0b1/fdb_record_layer/plans/index_plan.py +250 -0
  46. fdb_record_layer-0.1.0b1/fdb_record_layer/plans/intersection_plan.py +161 -0
  47. fdb_record_layer-0.1.0b1/fdb_record_layer/plans/scan_plan.py +186 -0
  48. fdb_record_layer-0.1.0b1/fdb_record_layer/plans/union_plan.py +171 -0
  49. fdb_record_layer-0.1.0b1/fdb_record_layer/query/__init__.py +95 -0
  50. fdb_record_layer-0.1.0b1/fdb_record_layer/query/comparisons.py +234 -0
  51. fdb_record_layer-0.1.0b1/fdb_record_layer/query/components.py +335 -0
  52. fdb_record_layer-0.1.0b1/fdb_record_layer/query/predicates.py +194 -0
  53. fdb_record_layer-0.1.0b1/fdb_record_layer/query/query.py +457 -0
  54. fdb_record_layer-0.1.0b1/fdb_record_layer/relational/__init__.py +51 -0
  55. fdb_record_layer-0.1.0b1/fdb_record_layer/relational/database.py +778 -0
  56. fdb_record_layer-0.1.0b1/fdb_record_layer/relational/result_set.py +400 -0
  57. fdb_record_layer-0.1.0b1/fdb_record_layer/relational/schema.py +429 -0
  58. fdb_record_layer-0.1.0b1/fdb_record_layer/relational/sql/__init__.py +225 -0
  59. fdb_record_layer-0.1.0b1/fdb_record_layer/relational/sql/ast.py +914 -0
  60. fdb_record_layer-0.1.0b1/fdb_record_layer/relational/sql/lexer.py +497 -0
  61. fdb_record_layer-0.1.0b1/fdb_record_layer/relational/sql/parser.py +1083 -0
  62. fdb_record_layer-0.1.0b1/fdb_record_layer/relational/sql/translator.py +684 -0
  63. fdb_record_layer-0.1.0b1/fdb_record_layer/relational/sql/types.py +666 -0
  64. fdb_record_layer-0.1.0b1/fdb_record_layer/serialization/__init__.py +0 -0
  65. fdb_record_layer-0.1.0b1/fdb_record_layer/serialization/proto_serializer.py +136 -0
  66. fdb_record_layer-0.1.0b1/fdb_record_layer/serialization/serializer.py +63 -0
  67. fdb_record_layer-0.1.0b1/fdb_record_layer/utils/__init__.py +162 -0
  68. fdb_record_layer-0.1.0b1/fdb_record_layer/utils/batch.py +478 -0
  69. fdb_record_layer-0.1.0b1/fdb_record_layer/utils/cache.py +646 -0
  70. fdb_record_layer-0.1.0b1/fdb_record_layer/utils/circuit_breaker.py +316 -0
  71. fdb_record_layer-0.1.0b1/fdb_record_layer/utils/health.py +389 -0
  72. fdb_record_layer-0.1.0b1/fdb_record_layer/utils/lifecycle.py +491 -0
  73. fdb_record_layer-0.1.0b1/fdb_record_layer/utils/logging.py +319 -0
  74. fdb_record_layer-0.1.0b1/fdb_record_layer/utils/metrics.py +744 -0
  75. fdb_record_layer-0.1.0b1/fdb_record_layer/utils/pool.py +442 -0
  76. fdb_record_layer-0.1.0b1/fdb_record_layer.egg-info/PKG-INFO +255 -0
  77. fdb_record_layer-0.1.0b1/fdb_record_layer.egg-info/SOURCES.txt +92 -0
  78. fdb_record_layer-0.1.0b1/fdb_record_layer.egg-info/dependency_links.txt +1 -0
  79. fdb_record_layer-0.1.0b1/fdb_record_layer.egg-info/requires.txt +18 -0
  80. fdb_record_layer-0.1.0b1/fdb_record_layer.egg-info/top_level.txt +1 -0
  81. fdb_record_layer-0.1.0b1/pyproject.toml +93 -0
  82. fdb_record_layer-0.1.0b1/setup.cfg +4 -0
  83. fdb_record_layer-0.1.0b1/tests/test_circuit_breaker.py +326 -0
  84. fdb_record_layer-0.1.0b1/tests/test_expressions.py +280 -0
  85. fdb_record_layer-0.1.0b1/tests/test_health.py +285 -0
  86. fdb_record_layer-0.1.0b1/tests/test_indexes.py +651 -0
  87. fdb_record_layer-0.1.0b1/tests/test_integration.py +590 -0
  88. fdb_record_layer-0.1.0b1/tests/test_lifecycle.py +250 -0
  89. fdb_record_layer-0.1.0b1/tests/test_logging.py +275 -0
  90. fdb_record_layer-0.1.0b1/tests/test_plans.py +618 -0
  91. fdb_record_layer-0.1.0b1/tests/test_query.py +468 -0
  92. fdb_record_layer-0.1.0b1/tests/test_sql_lexer.py +346 -0
  93. fdb_record_layer-0.1.0b1/tests/test_sql_parser.py +412 -0
  94. fdb_record_layer-0.1.0b1/tests/test_store.py +555 -0
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2024 FDB Record Layer Python Contributors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,255 @@
1
+ Metadata-Version: 2.4
2
+ Name: fdb-record-layer
3
+ Version: 0.1.0b1
4
+ Summary: Python implementation of FoundationDB Record Layer
5
+ Author: FDB Record Layer Python Contributors
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/foundationdb/fdb-record-layer-python
8
+ Project-URL: Documentation, https://foundationdb.github.io/fdb-record-layer-python
9
+ Project-URL: Repository, https://github.com/foundationdb/fdb-record-layer-python
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Database
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: foundationdb>=7.1.0
23
+ Requires-Dist: protobuf>=3.20.0
24
+ Requires-Dist: typing-extensions>=4.0.0
25
+ Provides-Extra: sql
26
+ Requires-Dist: lark>=1.0.0; extra == "sql"
27
+ Provides-Extra: grpc
28
+ Requires-Dist: grpcio>=1.50.0; extra == "grpc"
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
31
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
32
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
33
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
34
+ Provides-Extra: all
35
+ Requires-Dist: fdb-record-layer[dev,grpc,sql]; extra == "all"
36
+ Dynamic: license-file
37
+
38
+ # FDB Record Layer for Python
39
+
40
+ A Python implementation of the [FoundationDB Record Layer](https://github.com/FoundationDB/fdb-record-layer), providing a structured record-oriented store with secondary indexes, query planning, and SQL support on top of FoundationDB.
41
+
42
+ ## Features
43
+
44
+ - **Record Store**: Type-safe storage and retrieval of Protocol Buffer messages
45
+ - **Secondary Indexes**: Automatic index maintenance with VALUE, COUNT, RANK, and TEXT index types
46
+ - **Query System**: Declarative query API with cost-based optimization (Cascades planner)
47
+ - **SQL Support**: SQL parsing and execution with full DML/DDL support
48
+ - **Async/Await**: Native Python asyncio support throughout
49
+ - **Production Ready**: Connection pooling, circuit breakers, health checks, graceful shutdown
50
+
51
+ ## Installation
52
+
53
+ ```bash
54
+ pip install fdb-record-layer
55
+ ```
56
+
57
+ For SQL support:
58
+ ```bash
59
+ pip install fdb-record-layer[sql]
60
+ ```
61
+
62
+ For all optional dependencies:
63
+ ```bash
64
+ pip install fdb-record-layer[all]
65
+ ```
66
+
67
+ ## Requirements
68
+
69
+ - Python 3.10+
70
+ - FoundationDB 7.1+
71
+ - Protocol Buffers 3.20+
72
+
73
+ ## Quick Start
74
+
75
+ ### Define Your Schema
76
+
77
+ ```python
78
+ from fdb_record_layer import RecordMetaDataBuilder, Index, IndexTypes
79
+ from your_proto_pb2 import Person # Your protobuf message
80
+
81
+ # Build metadata with indexes
82
+ metadata = (
83
+ RecordMetaDataBuilder()
84
+ .add_record_type(Person)
85
+ .add_index(Index("person_by_name", "name"))
86
+ .add_index(Index("person_by_age", "age", index_type=IndexTypes.VALUE))
87
+ .build()
88
+ )
89
+ ```
90
+
91
+ ### Store and Query Records
92
+
93
+ ```python
94
+ from fdb_record_layer import FDBDatabase, FDBRecordStore
95
+
96
+ async def main():
97
+ # Connect to FoundationDB
98
+ db = FDBDatabase.open()
99
+
100
+ async with db.transaction() as tr:
101
+ # Open record store
102
+ store = await FDBRecordStore.open(tr, metadata, key_space_path=("myapp",))
103
+
104
+ # Save a record
105
+ person = Person(id=1, name="Alice", age=30)
106
+ await store.save_record(person)
107
+
108
+ # Query by index
109
+ async for record in store.scan_index("person_by_name", equals="Alice"):
110
+ print(f"Found: {record.name}")
111
+ ```
112
+
113
+ ### Using the Query Builder
114
+
115
+ ```python
116
+ from fdb_record_layer.query import Query, Field
117
+
118
+ # Build a query
119
+ query = (
120
+ Query.from_type("Person")
121
+ .where(Field("age").greater_than(25))
122
+ .where(Field("name").starts_with("A"))
123
+ .build()
124
+ )
125
+
126
+ # Execute
127
+ async for record in store.execute_query(query):
128
+ print(record)
129
+ ```
130
+
131
+ ### SQL Queries
132
+
133
+ ```python
134
+ from fdb_record_layer.relational import RelationalDatabase
135
+
136
+ async def main():
137
+ db = RelationalDatabase.open()
138
+
139
+ # Execute SQL
140
+ result = await db.execute("""
141
+ SELECT name, age FROM Person
142
+ WHERE age > 25
143
+ ORDER BY name
144
+ """)
145
+
146
+ async for row in result:
147
+ print(f"{row['name']}: {row['age']}")
148
+ ```
149
+
150
+ ## Key Expressions
151
+
152
+ Key expressions define how to extract keys from records for indexing:
153
+
154
+ ```python
155
+ from fdb_record_layer.expressions import field, concat, record_type
156
+
157
+ # Simple field
158
+ field("name")
159
+
160
+ # Composite key
161
+ concat(field("last_name"), field("first_name"))
162
+
163
+ # Nested field
164
+ field("address").nest("city")
165
+
166
+ # Include record type in key (for union indexes)
167
+ concat(record_type(), field("id"))
168
+ ```
169
+
170
+ ## Index Types
171
+
172
+ | Type | Description | Use Case |
173
+ |------|-------------|----------|
174
+ | VALUE | Standard B-tree index | Equality and range queries |
175
+ | COUNT | Aggregate count index | Fast COUNT(*) queries |
176
+ | SUM | Aggregate sum index | Fast SUM() queries |
177
+ | RANK | Skip-list based ranking | Leaderboards, percentiles |
178
+ | TEXT | Full-text search | Text search with tokenization |
179
+
180
+ ## Production Features
181
+
182
+ ### Connection Pooling
183
+
184
+ ```python
185
+ from fdb_record_layer.utils import ConnectionPool
186
+
187
+ pool = ConnectionPool(min_size=5, max_size=20)
188
+ async with pool.acquire() as conn:
189
+ # Use connection
190
+ pass
191
+ ```
192
+
193
+ ### Circuit Breaker
194
+
195
+ ```python
196
+ from fdb_record_layer.utils import get_circuit_breaker
197
+
198
+ breaker = get_circuit_breaker("fdb")
199
+ async with breaker:
200
+ await store.save_record(record)
201
+ ```
202
+
203
+ ### Health Checks
204
+
205
+ ```python
206
+ from fdb_record_layer.utils import get_health_checker
207
+
208
+ checker = get_health_checker()
209
+ report = await checker.check_health()
210
+ print(f"Status: {report.status}")
211
+ ```
212
+
213
+ ### Graceful Shutdown
214
+
215
+ ```python
216
+ from fdb_record_layer.utils import init_lifecycle
217
+
218
+ lifecycle = init_lifecycle()
219
+ # Handles SIGTERM/SIGINT, drains connections, runs cleanup hooks
220
+ ```
221
+
222
+ ## Documentation
223
+
224
+ - [API Reference](https://foundationdb.github.io/fdb-record-layer-python)
225
+ - [Java Record Layer Docs](https://foundationdb.github.io/fdb-record-layer/) (conceptual reference)
226
+
227
+ ## Development
228
+
229
+ ```bash
230
+ # Clone and install
231
+ git clone https://github.com/foundationdb/fdb-record-layer-python
232
+ cd fdb-record-layer-python
233
+ pip install -e .[dev]
234
+
235
+ # Run tests
236
+ pytest
237
+
238
+ # Type checking
239
+ mypy fdb_record_layer
240
+
241
+ # Linting
242
+ ruff check fdb_record_layer
243
+ ```
244
+
245
+ ## License
246
+
247
+ Apache License 2.0. See [LICENSE](LICENSE) for details.
248
+
249
+ ## Contributing
250
+
251
+ Contributions are welcome! Please read our contributing guidelines and submit pull requests.
252
+
253
+ ## Acknowledgments
254
+
255
+ This project is a Python port of the [FoundationDB Record Layer](https://github.com/FoundationDB/fdb-record-layer), originally developed by Apple.
@@ -0,0 +1,218 @@
1
+ # FDB Record Layer for Python
2
+
3
+ A Python implementation of the [FoundationDB Record Layer](https://github.com/FoundationDB/fdb-record-layer), providing a structured record-oriented store with secondary indexes, query planning, and SQL support on top of FoundationDB.
4
+
5
+ ## Features
6
+
7
+ - **Record Store**: Type-safe storage and retrieval of Protocol Buffer messages
8
+ - **Secondary Indexes**: Automatic index maintenance with VALUE, COUNT, RANK, and TEXT index types
9
+ - **Query System**: Declarative query API with cost-based optimization (Cascades planner)
10
+ - **SQL Support**: SQL parsing and execution with full DML/DDL support
11
+ - **Async/Await**: Native Python asyncio support throughout
12
+ - **Production Ready**: Connection pooling, circuit breakers, health checks, graceful shutdown
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pip install fdb-record-layer
18
+ ```
19
+
20
+ For SQL support:
21
+ ```bash
22
+ pip install fdb-record-layer[sql]
23
+ ```
24
+
25
+ For all optional dependencies:
26
+ ```bash
27
+ pip install fdb-record-layer[all]
28
+ ```
29
+
30
+ ## Requirements
31
+
32
+ - Python 3.10+
33
+ - FoundationDB 7.1+
34
+ - Protocol Buffers 3.20+
35
+
36
+ ## Quick Start
37
+
38
+ ### Define Your Schema
39
+
40
+ ```python
41
+ from fdb_record_layer import RecordMetaDataBuilder, Index, IndexTypes
42
+ from your_proto_pb2 import Person # Your protobuf message
43
+
44
+ # Build metadata with indexes
45
+ metadata = (
46
+ RecordMetaDataBuilder()
47
+ .add_record_type(Person)
48
+ .add_index(Index("person_by_name", "name"))
49
+ .add_index(Index("person_by_age", "age", index_type=IndexTypes.VALUE))
50
+ .build()
51
+ )
52
+ ```
53
+
54
+ ### Store and Query Records
55
+
56
+ ```python
57
+ from fdb_record_layer import FDBDatabase, FDBRecordStore
58
+
59
+ async def main():
60
+ # Connect to FoundationDB
61
+ db = FDBDatabase.open()
62
+
63
+ async with db.transaction() as tr:
64
+ # Open record store
65
+ store = await FDBRecordStore.open(tr, metadata, key_space_path=("myapp",))
66
+
67
+ # Save a record
68
+ person = Person(id=1, name="Alice", age=30)
69
+ await store.save_record(person)
70
+
71
+ # Query by index
72
+ async for record in store.scan_index("person_by_name", equals="Alice"):
73
+ print(f"Found: {record.name}")
74
+ ```
75
+
76
+ ### Using the Query Builder
77
+
78
+ ```python
79
+ from fdb_record_layer.query import Query, Field
80
+
81
+ # Build a query
82
+ query = (
83
+ Query.from_type("Person")
84
+ .where(Field("age").greater_than(25))
85
+ .where(Field("name").starts_with("A"))
86
+ .build()
87
+ )
88
+
89
+ # Execute
90
+ async for record in store.execute_query(query):
91
+ print(record)
92
+ ```
93
+
94
+ ### SQL Queries
95
+
96
+ ```python
97
+ from fdb_record_layer.relational import RelationalDatabase
98
+
99
+ async def main():
100
+ db = RelationalDatabase.open()
101
+
102
+ # Execute SQL
103
+ result = await db.execute("""
104
+ SELECT name, age FROM Person
105
+ WHERE age > 25
106
+ ORDER BY name
107
+ """)
108
+
109
+ async for row in result:
110
+ print(f"{row['name']}: {row['age']}")
111
+ ```
112
+
113
+ ## Key Expressions
114
+
115
+ Key expressions define how to extract keys from records for indexing:
116
+
117
+ ```python
118
+ from fdb_record_layer.expressions import field, concat, record_type
119
+
120
+ # Simple field
121
+ field("name")
122
+
123
+ # Composite key
124
+ concat(field("last_name"), field("first_name"))
125
+
126
+ # Nested field
127
+ field("address").nest("city")
128
+
129
+ # Include record type in key (for union indexes)
130
+ concat(record_type(), field("id"))
131
+ ```
132
+
133
+ ## Index Types
134
+
135
+ | Type | Description | Use Case |
136
+ |------|-------------|----------|
137
+ | VALUE | Standard B-tree index | Equality and range queries |
138
+ | COUNT | Aggregate count index | Fast COUNT(*) queries |
139
+ | SUM | Aggregate sum index | Fast SUM() queries |
140
+ | RANK | Skip-list based ranking | Leaderboards, percentiles |
141
+ | TEXT | Full-text search | Text search with tokenization |
142
+
143
+ ## Production Features
144
+
145
+ ### Connection Pooling
146
+
147
+ ```python
148
+ from fdb_record_layer.utils import ConnectionPool
149
+
150
+ pool = ConnectionPool(min_size=5, max_size=20)
151
+ async with pool.acquire() as conn:
152
+ # Use connection
153
+ pass
154
+ ```
155
+
156
+ ### Circuit Breaker
157
+
158
+ ```python
159
+ from fdb_record_layer.utils import get_circuit_breaker
160
+
161
+ breaker = get_circuit_breaker("fdb")
162
+ async with breaker:
163
+ await store.save_record(record)
164
+ ```
165
+
166
+ ### Health Checks
167
+
168
+ ```python
169
+ from fdb_record_layer.utils import get_health_checker
170
+
171
+ checker = get_health_checker()
172
+ report = await checker.check_health()
173
+ print(f"Status: {report.status}")
174
+ ```
175
+
176
+ ### Graceful Shutdown
177
+
178
+ ```python
179
+ from fdb_record_layer.utils import init_lifecycle
180
+
181
+ lifecycle = init_lifecycle()
182
+ # Handles SIGTERM/SIGINT, drains connections, runs cleanup hooks
183
+ ```
184
+
185
+ ## Documentation
186
+
187
+ - [API Reference](https://foundationdb.github.io/fdb-record-layer-python)
188
+ - [Java Record Layer Docs](https://foundationdb.github.io/fdb-record-layer/) (conceptual reference)
189
+
190
+ ## Development
191
+
192
+ ```bash
193
+ # Clone and install
194
+ git clone https://github.com/foundationdb/fdb-record-layer-python
195
+ cd fdb-record-layer-python
196
+ pip install -e .[dev]
197
+
198
+ # Run tests
199
+ pytest
200
+
201
+ # Type checking
202
+ mypy fdb_record_layer
203
+
204
+ # Linting
205
+ ruff check fdb_record_layer
206
+ ```
207
+
208
+ ## License
209
+
210
+ Apache License 2.0. See [LICENSE](LICENSE) for details.
211
+
212
+ ## Contributing
213
+
214
+ Contributions are welcome! Please read our contributing guidelines and submit pull requests.
215
+
216
+ ## Acknowledgments
217
+
218
+ This project is a Python port of the [FoundationDB Record Layer](https://github.com/FoundationDB/fdb-record-layer), originally developed by Apple.