1
- ObjectBox Python API
2
- ====================
3
- [ ObjectBox] ( https://objectbox.io ) is a superfast database for objects, now also available for Python (3.4+) with a simple CRUD API.
1
+ ObjectBox Python
2
+ ================
3
+ [ ObjectBox] ( https://objectbox.io ) Python is a lightweight yet powerful on-device database & vector database.
4
+ Store Python objects and vectors directly with an easy-to-use CRUD API while enjoying exceptional speed and efficiency.
4
5
And because it's an embedded database, there's no setup required.
5
6
6
7
Its advanced vector search empowers AI for a variety of applications, including RAG AI, generative AI,
7
- and similarity searches. Designed for high performance, the ObjectBox database is excellent for mobile and IoT devices,
8
- minimizing CPU, memory, and battery usage to enhance device efficiency and sustainability.
9
- As an offline-first solution, ObjectBox makes sure your app reliably works offline as well as online.
8
+ and similarity searches.
10
9
10
+ Designed for high performance, the ObjectBox database runs locally on-device.
11
+ As an offline-first solution, ObjectBox makes sure your app reliably works offline as well as online
12
+ (via [ Sync] ( https://objectbox.io/sync/ ) ).
11
13
12
- ## Table of Contents:
14
+ _ Table of Contents_
15
+
16
+ - [ Feature Highlights] ( #feature-highlights )
17
+ - [ Code Example (CRUD - Create, Read, Update, Delete)] ( #code-example-crud---create-read-update-delete )
13
18
- [ Getting Started] ( #getting-started )
14
- - [ Model IDs and UIDs] ( #model-ids-and-uids )
15
- - [ model.py] ( #modelpy )
16
- - [ Using ObjectBox] ( #using-objectbox )
17
- - [ Some features] ( #some-features )
18
- - [ Coming in the future] ( #coming-in-the-future )
19
+ - [ Alpha Notes] ( #alpha-notes )
19
20
- [ Help wanted] ( #help-wanted )
20
21
- [ Feedback] ( #feedback )
21
22
- [ License] ( #license )
22
23
23
- ---
24
-
25
- Getting started
26
- ---------------
27
- First of all, install the latest version:
28
-
29
- ``` bash
30
- pip install --upgrade objectbox
31
- ```
32
-
33
- To start using ObjectBox as a storage for your data, you need to define your model first.
34
- The model consists of Python classes annotated with ` @Entity ` decorator.
35
-
36
- ### Model IDs and UIDs
37
-
38
- Each Entity has to have an ID (unique among entities).
39
- Properties need an ID as well (unique inside one Entity).
40
- Both Entities and Properties must also have an UID, which is a globally unique identifier.
41
-
42
- For other ObjectBox supported languages, the binding takes care of assigning these IDs/UIDs but this feature is not yet implemented for Python.
43
- To learn more, see [ ObjectBox Java documentation] ( https://docs.objectbox.io/advanced/meta-model-ids-and-uids )
24
+ Feature Highlights
25
+ ------------------
44
26
45
- #### model.py
27
+ 🏁 ** On-device vector database** - for AI apps that work any place.\
28
+ 🏁 ** High performance** - superfast response rates enabling real-time applications.\
29
+ 🪂 ** ACID compliant** - Atomic, Consistent, Isolated, Durable.\
30
+ 🌱 ** Scalable** - grows with your app, handling millions of objects with ease.\
31
+ 💚 ** Sustainable** - frugal on CPU, Memory and battery / power use, reducing CO2 emissions.\
32
+ 💐 ** [ Queries] ( https://docs.objectbox.io/queries ) ** - filter data as needed, even across relations.\
33
+ 💻 ** Multiplatform** - Get native speed on your favorite platforms.\
34
+ * Linux x86-64 (64-bit)
35
+ * Linux ARMv6hf (e.g. Raspberry PI Zero)
36
+ * Linux ARMv7hf (e.g. Raspberry PI 3)
37
+ * Linux ARMv8 (e.g. Raspberry PI 4, 5, etc.)
38
+ * MacOS x86-64 and arm64 (Intel 64-bit and Apple Silicon)
39
+ * Windows x86-64 (64-bit)
46
40
47
- ``` python
48
- from objectbox.model import *
49
-
50
- @Entity (id = 1 , uid = 1 )
51
- class Person :
52
- id = Id(id = 1 , uid = 1001 )
53
- name = Property(str , id = 2 , uid = 1002 )
54
- is_enabled = Property(bool , id = 3 , uid = 1003 )
55
- # int can be stored with 64 (default), 32, 16 or 8 bit precision.
56
- int64 = Property(int , id = 4 , uid = 1004 )
57
- int32 = Property(int , type = PropertyType.int, id = 5 , uid = 1005 )
58
- int16 = Property(int , type = PropertyType.short, id = 6 , uid = 1006 )
59
- int8 = Property(int , type = PropertyType.byte, id = 7 , uid = 1007 )
60
- # float can be stored with 64 or 32 (default) bit precision.
61
- float64 = Property(float , id = 8 , uid = 1008 )
62
- float32 = Property(float , type = PropertyType.float, id = 9 , uid = 1009 )
63
- byte_array = Property(bytes , id = 10 , uid = 1010 )
64
- # Regular properties are not stored.
65
- transient = " "
66
- ```
67
-
68
- ### Using ObjectBox
41
+ #### Code Example (CRUD - Create, Read, Update, Delete)
69
42
70
- To actually use the database, you create a Store with the model you've just defined.
71
- Afterwards, you can reuse the instance (` store ` in the example below) and use it to access "Entity Boxes" which hold your objects.
72
-
73
- #### program.py
43
+ What does using ObjectBox in Python look like?
74
44
75
45
``` python
76
46
import objectbox
47
+
77
48
# from mypackage.model import Person
78
49
79
- # Configure ObjectBox: should be done only once in the whole program and the "store" variable should be kept around
80
- model = objectbox.Model()
81
- model.entity(Person, last_property_id = objectbox.model.IdUid(10 , 1010 ))
82
- model.last_entity_id = objectbox.model.IdUid(1 , 1 )
50
+ # The ObjectBox Store represents a database; keep it around...
83
51
store = objectbox.Store(model = model)
84
52
85
- # Open the box of "Person" entity. This can be called many times but you can also pass the variable around
53
+ # Get a box for the "Person" entity; a Box is the main interaction point with objects and the database.
86
54
box = store.box(Person)
87
55
88
56
person = Person()
@@ -94,65 +62,44 @@ box.put(person) # Update
94
62
box.remove(person) # Delete
95
63
```
96
64
97
- Additionally, see the [ TaskList example app] ( https://github.com/objectbox/objectbox-python/tree/main/example ) . After checking out this repository to run the example:
65
+ Getting started
66
+ ---------------
67
+ To install or update the latest version of ObjectBox, run this:
68
+
69
+ ``` bash
70
+ pip install --upgrade --pre objectbox # "--pre" because you want to get the 4.0.0 alpha version
98
71
```
99
- // Set up virtual environment, download ObjectBox libraries
100
- make depend
72
+ Now you are ready to use ObjectBox in your Python project.
101
73
102
- // Activate virtual environment...
103
- // ...on Linux
104
- source .venv/bin/activate
105
- // ...on Windows
106
- .venv\Scripts\activate
74
+ Head over to the ** [ ObjectBox documentation] ( https://docs.objectbox.io ) **
75
+ and learn how to setup your first entity classes.
107
76
108
- // Run the example
109
- python3 -m example
77
+ ### Examples
110
78
111
- // Once done, leave the virtual environment
112
- deactivate
113
- ```
79
+ Do you prefer to dive right into working examples?
80
+ We have you covered in the [ example] ( example/ ) folder.
81
+ It comes with a task list application and a vector search example using cities.
82
+ Additionally, for AI enthusiasts, we provide an "ollama" example,
83
+ which integrates a local LLM (via [ ollama] ( https://ollama.com ) )
84
+ with ObjectBox to manage and search embeddings effectively.
114
85
115
- For more information and code examples, see the tests folder. The docs for other languages may also help you understand the basics.
116
-
117
- * ObjectBox Java/Dart/Flutter - https://docs.objectbox.io
118
- * ObjectBox Go - https://golang.objectbox.io
119
- * ObjectBox Swift - https://swift.objectbox.io
120
-
121
- Some features
122
- -------------
123
- * Automatic transactions (ACID compliant)
124
- * Bulk operations
125
- * Vector types, e.g. for AI vector embeddings
126
- * Platforms supported with native speed:
127
- * Linux x86-64 (64-bit)
128
- * Linux ARMv6hf (e.g. Raspberry PI Zero)
129
- * Linux ARMv7hf (e.g. Raspberry PI 3; available only on request)
130
- * Linux ARMv8 (e.g. Raspberry PI 4)
131
- * MacOS x86-64 and arm64 (Intel 64-bit and Apple Silicon)
132
- * Windows x86-64 (64-bit)
133
-
134
- Coming in the future
135
- --------------------
136
- The goodness you know from the other ObjectBox language-bindings, e.g.,
137
-
138
- * model management (no need to manually set id/uid)
139
- * automatic model migration (no schema upgrade scripts etc.)
140
- * powerful queries
141
- * relations (to-one, to-many)
142
- * asynchronous operations
143
- * secondary indexes
86
+ Alpha Notes
87
+ -----------
88
+ While ObjectBox Python is powered by a rock stable core written in C/C++, we label our Python binding still "alpha."
89
+ We do this to manage expectations as some quality of life improvements are yet to come to our Python binding.
90
+ This is mostly about "model management," which still requires you to do some manual coding setup, e.g. for model IDs.
91
+ The final release will take care of this for you automatically.
144
92
145
93
Help wanted
146
94
-----------
147
- ObjectBox for Python is still in an early stage with limited feature set (compared to our other supported languages).
148
- To bring all these features to Python, we're asking the community to help out. PRs are more than welcome!
95
+ ObjectBox for Python is open to contributions.
149
96
The ObjectBox team will try its best to guide you and answer questions.
150
97
See [ CONTRIBUTING.md] ( https://github.com/objectbox/objectbox-python/blob/main/CONTRIBUTING.md ) to get started.
151
98
152
99
Feedback
153
100
--------
154
- Also, please let us know your feedback by opening an issue: for example, if you experience errors or if you have ideas
155
- for how to improve the API. Thanks!
101
+ We are looking for your feedback!
102
+ Please let us know what you think about ObjectBox for Python and how we can improve it.
156
103
157
104
License
158
105
-------
0 commit comments