Skip to content

Commit 887cb94

Browse files
author
Ivan Dlugos
committed
update readme
1 parent 8985967 commit 887cb94

1 file changed

Lines changed: 80 additions & 16 deletions

File tree

README.md

Lines changed: 80 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,60 @@
11
ObjectBox Python API
2-
================
3-
ObjectBox is a superfast database for objects, now also available for Python.
2+
====================
3+
ObjectBox is a superfast database for objects, now also available for Python with a simple CRUD API.
44

5-
ObjectBox persists your native Python classes using a simple CRUD API:
5+
* Latest release: v0.1.0
6+
* Python version: 3.4+
7+
* Platforms supported:
8+
* Linux 64-bit
9+
* Linux ARMv6hf (e.g. Raspberry PI Zero)
10+
* Linux ARMv7hf (e.g. Raspberry PI 3)
11+
* MacOS 64-bit
612

13+
Getting started
14+
---------------
15+
First of all, install the latest version:
16+
```bash
17+
pip install objectbox
18+
```
19+
20+
To start using ObjectBox as a storage for your data, you need to define your model first.
21+
The model consists of Python classes annotated with `@Entity` decorator.
22+
23+
### Model IDs and UIDs
24+
Each Entity has to have an ID (unique among entities).
25+
Properties need an ID as well (unique inside one Entity).
26+
Both Entities and Properties must also have an UID which is a globally unique identifier.
27+
28+
For other ObjectBox supported languages the binding takes care of assigning these IDs/UIDs but this feature is not yet implemented for Python.
29+
To learn more, see ObjectBox Java documentation: https://docs.objectbox.io/advanced/meta-model-ids-and-uids
30+
31+
#### model.py
732
```python
8-
# model.py
33+
from objectbox.model import *
34+
935
@Entity(id=1, uid=1)
1036
class Person:
1137
id = Id(id=1, uid=1001)
1238
first_name = Property(str, id=2, uid=1002)
1339
last_name = Property(str, id=3, uid=1003)
40+
```
41+
42+
### Using ObjectBox
43+
To actually use the database, you launch (or "build") it with the model you've just defined.
44+
Afterwards, you can reuse the instance (`ob` in the example bellow) and use it to access "Entity Boxes" which hold your objects.
45+
46+
#### program.py
47+
```python
48+
import objectbox
49+
# from mypackage.model import Person
50+
51+
# Configure ObjectBox - should be done only once in the whole program and the "ob" variable should be kept around
52+
model = objectbox.Model()
53+
model.entity(Person, last_property_id=objectbox.model.IdUid(3, 1003))
54+
model.last_entity_id = objectbox.model.IdUid(1, 1)
55+
ob = objectbox.Builder().model(model).directory("db").build()
1456

15-
# program.py
57+
# Open the box of "Person" entity. This can be called many times but you can also pass the variable around
1658
box = objectbox.Box(ob, Person)
1759

1860
id = box.put(Person(first_name="Joe", last_name="Green")) # Create
@@ -22,16 +64,18 @@ box.put(person) # Update
2264
box.remove(person) # Delete
2365
```
2466

25-
For more information and code examples see the tests folder.
26-
27-
Latest release: v0.1.0
67+
For more information and code examples see the tests folder as well as docs for other languages which may help you understand the basics.
68+
* ObjectBox Java = https://docs.objectbox.io
69+
* ObjectBox Go - https://golang.objectbox.io
70+
* ObjectBox Swift - https://swift.objectbox.io
2871

2972
Some features
3073
-------------
3174
* automatic transactions (ACID compliant)
3275
* bulk operations
3376

34-
# Coming soon
77+
Coming in the future
78+
-------------
3579
The goodness you know from other language-bindings ObjectBox has, e.g.:
3680
* model management (no need to manually set id/uid)
3781
* automatic model migration (no schema upgrade scripts etc.)
@@ -40,22 +84,42 @@ The goodness you know from other language-bindings ObjectBox has, e.g.:
4084
* asynchronous operations
4185
* secondary indexes
4286

43-
Installation
87+
Contributing
4488
------------
45-
To get started with ObjectBox you can get the repository code.
89+
Currently, the Python binding is in it's very early stages and lots of features available in other languages is missing here.
90+
If you have requests for specific feature, please open an issue. If you want to contribute, please feel free to open a PR.
91+
In case it's a non-obvious contribution it might be better to discuss and align first in an issue.
92+
4693
This repo uses `virtualenv` when installing packages so in case you don't have it yet: `pip install virtualenv`.
4794

48-
The main prerequisite to using the Python APIs is the ObjectBox binary library (.so, .dylib, .dll depending on your platform) which actually implements the database functionality.
95+
The main prerequisite to using the Python APIs is the ObjectBox binary library (.so, .dylib, .dll depending on your platform) which actually implements the database functionality.
96+
97+
The library should be placed in the `objectbox/lib/[architecture]/` folder of the checked out repository.
98+
99+
### Getting ObjectBox C-API library from pip
100+
The easiest way is to get all the binaries from the latest release in PyPI.
101+
```bash
102+
pip download objectbox
103+
unzip objectbox*.whl
104+
cp -r objectbox/lib [/path/to/your/git/objectbox/checkout]/objectbox/
105+
```
106+
107+
### Downloading from the ObjectBox-C release
108+
Alternatively, you can get the appropriate release from the ObjectBox-C repository.
109+
However, you need to pay attention to the required version - see `required_version` in `objectbox/c.py`.
49110
In the [ObjectBox C repository](https://github.com/objectbox/objectbox-c), you should find a download.sh script you can run.
50-
Follow the instructions and type Y when it asks you if it should install the library.
111+
112+
51113
```bash
52-
bash <(curl https://raw.githubusercontent.com/objectbox/objectbox-c/master/download.sh)
114+
wget https://raw.githubusercontent.com/objectbox/objectbox-c/master/download.sh
115+
chmod +x download.sh
116+
# replace [required_version] with the appropriate string then type N when the script asks about installing the library
117+
./download.sh [required_version]
118+
cp lib/*objectbox* [/path/to/your/git/objectbox/checkout]/objectbox/lib/$(uname -m)/
53119
```
54120

55121
You can run `make test` to make sure everything works as expected.
56122

57-
Required Python version: 3.4+
58-
59123
License
60124
-------
61125
Copyright 2019 ObjectBox Ltd. All rights reserved.

0 commit comments

Comments
 (0)