Skip to content

Commit 7dcf4a2

Browse files
committed
Merge branch '56-flatten-model-api' into 'dev'
Resolve "Integrated Model API into Top-Level API" See merge request objectbox/objectbox-python!46
2 parents 8b5c01f + 22438f4 commit 7dcf4a2

File tree

10 files changed

+51
-25
lines changed

10 files changed

+51
-25
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ Feature Highlights
4343
What does using ObjectBox in Python look like?
4444

4545
```python
46-
import objectbox
46+
from objectbox import *
4747

48-
# from mypackage.model import Person
48+
@Entity()
49+
class Person:
50+
id = Id
51+
name = String
4952

5053
# The ObjectBox Store represents a database; keep it around...
51-
store = objectbox.Store(model=model)
54+
store = Store()
5255

5356
# Get a box for the "Person" entity; a Box is the main interaction point with objects and the database.
5457
box = store.box(Person)

example/ollama/main.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
# using objectbox as a vector store
33

44
import ollama
5-
import objectbox
6-
from objectbox.model import *
7-
from objectbox.model.properties import *
5+
from objectbox import *
86

97
documents = [
108
"Llamas are members of the camelid family meaning they're pretty closely related to vicuñas and camels",
@@ -16,7 +14,7 @@
1614
]
1715

1816
# Have fresh data for each start
19-
objectbox.Store.remove_db_files("objectbox")
17+
Store.remove_db_files("objectbox")
2018

2119
@Entity()
2220
class DocumentEmbedding:
@@ -27,7 +25,7 @@ class DocumentEmbedding:
2725
distance_type=VectorDistanceType.COSINE
2826
))
2927

30-
store = objectbox.Store()
28+
store = Store()
3129
box = store.box(DocumentEmbedding)
3230

3331
print("Documents to embed: ", len(documents))

example/tasks/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from cmd import Cmd
2-
import objectbox
3-
from objectbox.model import *
2+
from objectbox import *
43
import time
54

65
@Entity()
@@ -24,7 +23,7 @@ def format_date(timestamp_ms: int) -> str:
2423

2524
class TasklistCmd(Cmd):
2625
prompt = "> "
27-
_store = objectbox.Store(directory="tasklist-db")
26+
_store = Store(directory="tasklist-db")
2827
_box = _store.box(Task)
2928

3029
def do_ls(self, _):

example/vectorsearch-cities/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from cmd import Cmd
2-
import objectbox
3-
from objectbox.model import *
2+
from objectbox import *
43
import time
54
import csv
65
import os
@@ -32,7 +31,7 @@ def __init__(self, *args):
3231
Cmd.__init__(self, *args)
3332
dbdir = "cities-db"
3433
new_db = not os.path.exists(dbdir)
35-
self._store = objectbox.Store(directory=dbdir)
34+
self._store = Store(directory=dbdir)
3635
self._box = self._store.box(City)
3736
if new_db:
3837
with open(os.path.join(os.path.dirname(__file__), 'cities.csv')) as f:

objectbox/__init__.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from objectbox.box import Box
1717
from objectbox.builder import Builder
18-
from objectbox.model import Model
18+
from objectbox.model import Model, Entity, Id, String, Index, Bool, Int8, Int16, Int32, Int64, Float32, Float64, Bytes, BoolVector, Int8Vector, Int16Vector, Int32Vector, Int64Vector, Float32Vector, Float64Vector, CharVector, BoolList, Int8List, Int16List, Int32List, Int64List, Float32List, Float64List, CharList, Date, DateNano, Flex, HnswIndex, VectorDistanceType
1919
from objectbox.store import Store
2020
from objectbox.objectbox import ObjectBox
2121
from objectbox.c import NotFoundException, version_core, DebugFlags
@@ -25,6 +25,39 @@
2525
'Box',
2626
'Builder',
2727
'Model',
28+
'Entity',
29+
'Id',
30+
'Bool',
31+
'Int8',
32+
'Int16',
33+
'Int32',
34+
'Int64',
35+
'Float32',
36+
'Float64',
37+
'Bytes',
38+
'String',
39+
'BoolVector',
40+
'Int8Vector',
41+
'Int16Vector',
42+
'Int32Vector',
43+
'Int64Vector',
44+
'Float32Vector',
45+
'Float64Vector',
46+
'CharVector',
47+
'BoolList',
48+
'Int8List',
49+
'Int16List',
50+
'Int32List',
51+
'Int64List',
52+
'Float32List',
53+
'Float64List',
54+
'CharList',
55+
'Date',
56+
'DateNano',
57+
'Flex',
58+
'Index',
59+
'HnswIndex',
60+
'VectorDistanceType',
2861
'Store',
2962
'ObjectBox',
3063
'NotFoundException',

tests/common.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
import pytest
33
import objectbox
44
from objectbox.logger import logger
5-
from objectbox.store import Store
65
from tests.model import *
76
import numpy as np
8-
from datetime import timezone
9-
7+
from datetime import datetime, timezone
8+
from objectbox import *
109

1110
def remove_json_model_file():
1211
path = os.path.dirname(os.path.realpath(__file__))
@@ -16,7 +15,7 @@ def remove_json_model_file():
1615

1716

1817
def create_default_model():
19-
model = objectbox.Model()
18+
model = Model()
2019
model.entity(TestEntity)
2120
model.entity(TestEntityDatetime)
2221
model.entity(TestEntityFlex)

tests/model.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from objectbox.model import *
2-
from datetime import datetime
3-
1+
from objectbox import *
42

53
@Entity()
64
class TestEntity:

tests/test_internals.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from objectbox import *
2-
from objectbox.model import *
32
from objectbox.model.idsync import sync_model
43

54
import os

tests/test_query.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import objectbox
22
from objectbox import *
3-
from objectbox.model import *
43
from objectbox.c import *
54
from objectbox.query import *
65
import pytest

tests/test_userclass.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from objectbox import *
2-
from objectbox.model import *
32
from objectbox.model.idsync import sync_model
43

54
def test_userclass():

0 commit comments

Comments
 (0)