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