Repository navigation
Releases
ObjectBox Python 5.0: 3x faster than SQLite ORMs, now with Sync
ObjectBox Python 5.0 is the biggest update of the Python binding yet: it is much faster, syncs your data, has relations, unique constraints and a more complete query API, and installs smaller, platform-specific packages.
pip install objectbox # or, to use ObjectBox Sync: pip install objectbox-syncAbout 3x faster than the Python ORMs on SQLite
How does an embedded object database compare to SQLite accessed via the popular Python ORMs (SQLAlchemy, SQLModel,
Django, peewee, Tortoise ORM, ...)? We benchmarked it: in python-orm-benchmarks, ObjectBox has the best result in all three tests, about 3x the best SQL ORM (rows per second, geometric mean of 9 operations: get, queries, inserts, updates and deletes):
The benchmark runs everything in-process on local storage, times only the database work and reports the median of
5 runs; see the benchmark repository for the setup, result details and how to run it yourself.
It used the new, still experimental FlatBuffers codegen, which you enable with one line:
import objectbox.experimental
objectbox.experimental.enable_flatbuffers_codegen() # generates the code to write and read objects per entityRelations and more powerful queries
- To-one relations:
customer_id = Relation(Customer)stores the ID of the related object; ObjectBox knows the target, e.g. removing it resets the relation. - Link queries over relations, like in Java and Dart:
link()andbacklink(), across any number of relations. - New conditions and options: ordering (
order(),OrderFlags),one_of()/not_one_of(),is_null(),datetimevalues in date conditions. - New query methods:
find_first(),find_unique()anddescribe(); change values of a built query withset_parameter(). - Vector search:
nearest_neighbors(query_vector, max_result_count); scored results are named tuples (result.object,result.score). - Queries are freed:
with box.query(...).build() as query:closes a query right away (the garbage collector and closing the store do too); before, every built query kept its native memory.
Data model and objects
- Unique constraints:
email = String(unique=Unique()), optionally replacing the conflicting object (ConflictStrategy.REPLACE). - Indexes: strings get a hash index by default, like in the other ObjectBox languages
(Index(IndexType.VALUE)for e.g.starts_with()); indexes and other property flags can now be changed later. - Self-assigned IDs:
Id(assignable=True). Without it, putting an object with an ID that ObjectBox did not assign now raises, which prevents data loss. - Boxes:
put()of a list returns the IDs, newremove_many(),contains(),get_many()andupdate();Nonevalues are stored as null. - Model file: removed entities and properties are recorded as retired UIDs, and fields of other ObjectBox languages are kept, so
objectbox-model.jsoncan be shared with them and the ObjectBox Generator.
Installation and platforms
- Smaller downloads: the ObjectBox library comes in one wheel per platform (
objectbox-clib) instead of one package with the libraries for all platforms; the Python code is inobjectbox-api, andobjectboxinstalls both. - New platforms: Windows ARM64, and 32-bit Python on a 64-bit Linux kernel (e.g. Raspberry Pi OS 32-bit).
- Requirements: Python 3.7 or newer; ObjectBox library 5.3.2.
Linux ARMv6 (e.g. Raspberry Pi Zero/1) is no longer supported, as PyPI has no wheels for it.
ObjectBox Sync for Python
Synchronize your data with an ObjectBox Sync Server, and through it with MongoDB: install objectbox-sync instead of objectbox, mark entities with @SyncEntity() and start a client:
from objectbox import Entity, Id, String, Store, Sync, SyncCredentials, SyncEntity
@SyncEntity()
@Entity()
class Task:
id = Id
text = String
store = Store()
client = Sync.client(store, "ws://127.0.0.1:9999", SyncCredentials.none())
client.start() # syncs in the background, also when offline at firstIncludes authentication (JWT), Sync filter variables, listeners for login, connection, completion and data changes, and SyncClock/SyncPrecedence properties for conflict resolution.
Property names are now stored in camelCase (date_created as dateCreated), like in the other ObjectBox languages, so Python apps share a data model with apps in Java, Kotlin, Dart or Swift.
⚠️ Breaking changes
Warning
Upgrading from 4.x with pip? Uninstall first: pip uninstall objectbox, then pip install objectbox.
An in-place pip install --upgrade objectbox breaks the installation
(repair it with pip install --force-reinstall --no-deps objectbox-api).
Fresh installs and upgrades with uv are not affected.
Most code keeps working; check these:
- Property names are stored in camelCase; existing databases and model files are migrated automatically (see
@Entity(python_names=True)to keep the Python names). - Putting an object with an ID that ObjectBox did not assign raises (use
Id(assignable=True)). - String properties with
Index()get a hash index (migrated when the store opens). - Exceptions: all derive from
DbError(replacingCoreExceptionandNotFoundException); wrong arguments raiseTypeErrororIllegalArgumentError. - Property classes take no
id=argument (it was ignored);uid=is keyword-only. - The typed
set_parameter_*()methods are replaced byset_parameter(); a query builder can not be reused afterbuild().
See the CHANGELOG for all changes.
Learn more
- Python docs (Python tabs) and Sync docs
- Examples: tasks, vector search, RAG with Ollama
- Coding with an AI agent? The ObjectBox agent skill helps it to write
correct ObjectBox code:npx skills add objectbox/objectbox-skills
Vector Search for Python: Objectbox 4.0.0
- ObjectBox now supports vector search ("vector database") to enable efficient similarity searches.
This is particularly useful for AI/ML/RAG applications, e.g. image, audio, or text similarity.
Other use cases include sematic search or recommendation engines.
See https://docs.objectbox.io/ann-vector-search for details. - The definition of entities (aka the data model) is now greatly simplified
- Type-specific property classes, e.g.
name: String,count: Int64,score: Float32 - Automatic ID/UID and model management (i.e. add/remove/rename of entities and properties)
- Automatic discovery of @entity classes
- Type-specific property classes, e.g.
- Queries: property-based conditions, e.g.
box.query(City.name.starts_with("Be")) - Queries: logical operators, e.g.
box.query(City.name == "Berlin" | City.name == "Munich") - Convenient "Store" API (deprecates ObjectBox and Builder API)
- New examples added, illustrating an VectorSearch and AI/RAG application
- Stable flat public API provided by single top-level module objectbox
- Dependency flatbuffers: Updated to 24.3.50
- Adjusting the version number to match the core version (4.0); we will be aligning on major versions from now on.
V4.0.0 Alpha Vector Search
- ObjectBox now supports vector search ("vector database") to enable efficient similarity searches.
This is particularly useful for AI/ML/RAG applications, e.g. image, audio, or text similarity.
Other use cases include sematic search or recommendation engines.
See https://docs.objectbox.io/ann-vector-search for details. - Queries: support for Property-based conditions and logic combinations
- Convenient "Store" API deprecates ObjectBox and Builder API
- New examples added, illustrating an VectorSearch and AI/RAG application
- Dependency flatbuffers: Updated to 24.3.50
- Adjusting the version number to match the core version (4.0); we will be aligning on major versions from now on.
v0.6.1 Support for in-memory database
The new version 0.6(.1) for the Python database comes with:
- In-memory databases (by using directory path prefix "
memory:") - numpy dependency fix
- Update objectbox-c to v0.21.0 with many improvements (details)
v0.5.0 Vector and Date Types
The new version 0.5 for the Python database brings new types:
- vector types allow efficient storage of numeric lists (and Numpy arrays), e.g. for vector embeddings in AI applications
- Date types with millisecond and nanosecond precision
More info is available at: https://objectbox.io/vector-database-flutter/
