Skip to main content

Blitz-DB3

Build Status PyPI

BlitzDB3 is a port of BlitzDB to Python 3. We're using BlitzDB on some internal projects at Abilian and needed these changes to migrate these projects to Python 3.

BlitzDB, or just Blitz is a document-based, object-oriented, transactional database written purely in Python. Among other things, it provides a powerful querying language, deep indexing of documents, compressed data storage and automatic referencing of embedded documents. It is reasonably fast, can be easily embedded in any Python application and does not have any external dependencies (except when using a third-party backend). In addition, you can use it as a frontend to other database engines such as MongoDB in case you should need more power.

Key Features

  • Document-based, object-oriented interface.
  • Powerful and rich querying language.
  • Deep document indexes on arbitrary fields.
  • Compressed storage of documents.
  • Support for multiple backends (e.g. file-based storage, MongoDB).
  • Support for database transactions (currently only for the file-based backend).

Use Cases

Blitz can be used as a standalone document store for client application. Originally blitz was designed for use with the checkmate Python code analysis toolkit, where it stores statistical data. Since blitz stores all documents as single JSON files, it is possible to put the whole database under version-control.

Installation

The easiest way to install Blitz is through pip or easy_install

pip install blitzdb
#or...
easy_install blitzdb

For more detailed installation instructions, have a look at the documentation.

Detailed Documentation

The detailed documentation for this project is hosted on ReadTheDocs, feel free to take a look!

Roadmap

  • 3.2 (unreleased): keep fixing and upgrading.

Changelog

  • 3.1: drop support for Python 2.
  • 3.0a1: Port to Python 3 using six. Cleanup and format code.

Old Changelog (original Blitzdb by Andreas Dewes / andreas@7scientists.com)

  • 0.4.4: SQL backend: Do not coerce server_default values via a CAST, as this can cause incompatibilities.
  • 0.4.3: Many small improvements to the SQL backend.
  • 0.3.0: Fully functional SQL backend.
  • 0.2.12: Added support for proper attribute iteration to Document.
  • 0.2.11: Allow setting the collection parameter through a Document.Meta attribute.
  • 0.2.10: Bugfix-Release: Fix Python 3 compatibility issue.
  • 0.2.9: Bugfix-Release: Fix serialization problem with file backend.
  • 0.2.8: Added get, has_key and clear methods to Document class
  • 0.2.7: Fixed problem with unicode function in Python 3.
  • 0.2.6: Bugfix-Release: Fixed an issue with the $exists operator for the file backend.
  • 0.2.5: Bugfix-Release
  • 0.2.4: Added support for projections and update operations to the MongoDB backend.
  • 0.2.3: Bugfix-Release: Fixed bug in transaction data caching in MongoDB backend.
  • 0.2.2: Fix for slice operators in MongoDB backend.
  • 0.2.1: Better tests.
  • 0.2.0: Support for including additional information in DB references. Support for accessing document attributes as dictionary items. Added $regex parameter that allows to use regular expressions in queries.
  • 0.1.5: MongoDB backend now supports database transactions. Database operations are now read-isolated by default, i.e. uncommitted operations will not affect database queries before they are committed.
  • 0.1.4: Improved indexing of objects for the file backend, added support for automatic serialization/deserialization of object attributes when adding keys to or querying an index.
  • 0.1.3: Sorting of query sets is now supported (still experimental)
  • 0.1.2: Small bugfixes, BlitzDB version number now contained in DB config dict
  • 0.1.1: BlitzDB is now Python3 compatible (thanks to David Koblas)

Contributors (in alphabetical order)

Current maintainer (BlitzDB3)

  • Stefane Fermigier - @sfermigier

Original author (BlitzDB)

  • Andreas Dewes - @adewes

Original contributors

  • @bwiessneth
  • Florian Lehmann - @cashaddy
  • Karskrin - @cBrauge
  • Chris Mutel - @cmutel
  • Cecil Woebker - @cwoebker
  • Ethan Blackburn - @EthanBlackburn
  • Javier Collado - @jcollado
  • Jason Xie - @jxieeducation
  • David Koblas - @koblas
  • Stéphane Wirtel - @matrixise
  • Victor Miclovich - @miclovich
  • Dmytro Kyrychuk - @orgkhnargh
  • Christoph Neumann - @programmdesign
  • Dale - @puredistortion
  • tjado - @tejado
  • Thomas Ballinger - @thomasballinger
  • Tyler Kennedy - @TkTech
  • Toby Champion - @tobych

Thanks for all your contributions, without you BlitzDB wouldn't be what it is today :)

Third-Party Contributions

  • Flask-BlitzDB Flask adapter for BlitzDB. Blitz + Flask = Awesome!

Examples

To get an idea of what you can do with Blitz, here are some examples.

Creating objects

from blitzdb import Document

class Movie(Document):
    pass

class Actor(Document):
    pass

the_godfather = Movie({'name': 'The Godfather','year':1972,'pk': 1})

marlon_brando = Actor({'name':'Marlon Brando','pk': 1})
al_pacino = Actor({'name' : 'Al Pacino','pk': 1})

Storing objects in the database:

from blitzdb import FileBackend

backend = FileBackend("/path/to/my/db")

the_godfather.save(backend)
marlon_brando.save(backend)
al_pacino.save(backend)

Retrieving objects from the database:

the_godfather = backend.get(Movie, {'pk': 1})
#or...
the_godfather = backend.get(Movie, {'name' : 'The Godfather'})

Filtering objects

movies_from_1972 = backend.filter(Movie, {'year' : 1972})

Working with transactions

backend.begin()
the_godfather.director = 'Roland Emmerich' #oops...
the_godfather.save()
backend.rollback() #undo the changes...

Creating nested object references

the_godfather.cast = {'Don Vito Corleone' : marlon_brando, 'Michael Corleone' : al_pacino}

#Documents stored within other objects will be automatically converted to database references.

marlon_brando.performances = [the_godfather]
al_pacino.performances = [the_godfather]

marlon_brando.save(backend)
al_pacino.save(backend)
the_godfather.save(backend)
#Will store references to the movies within the documents in the DB

Creation of database indexes and advanced querying

backend.create_index(Actor,'performances')
#Will create an index on the 'performances' field, for fast querying

godfather_cast = backend.filter(Actor,{'movies' : the_godfather})
#Will return 'Al Pacino' and 'Marlon Brando'

Arbitrary filter expressions

star_wars_iv = Movie({'name' : 'Star Wars - Episode IV: A New Hope','year': 1977})
star_wars_iv.save()

movies_from_the_seventies = backend.filter(Movie,{'year': lambda year : year >= 1970 and year < 1980})
#Will return Star Wars & The Godfather (man, what a decade!)

Metadata

Release files for blitzdb3 3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blitzdb3 3.1
File Size Uploaded
blitzdb3-3.1.tar.gz 53.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for blitzdb3 3.1
File Interpreter ABI Platform
blitzdb3-3.1-py3-none-any.whl Python 3 none any Details

Total release size: 112.4 kB

Release files / blitzdb3-3.1.tar.gz

Download URL blitzdb3-3.1.tar.gz
Size 53.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ab7f956be1d05810444c2f8b3459b5e9c31d98bce25c49a8f6b9a6959ee9a77a
BLAKE2b-256 checksum
How to use checksums
8c635ba5dc23a133df80334a296d1a04358dadad58b6647f8be491cb25722238
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.6.10 Darwin/17.7.0

Release files / blitzdb3-3.1-py3-none-any.whl

Download URL blitzdb3-3.1-py3-none-any.whl
Size 59.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8cb391e8180435f1aac42468c5458412a9cb10fdb767ea70ee75780b72728539
BLAKE2b-256 checksum
How to use checksums
6b39d0ffbaaa962e0e6829e96a759abb92a59608140bbb758e0ae6cac1123976
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.6.10 Darwin/17.7.0

Release history Release notifications | RSS feed

This release

3.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page