• Stars
    star
    329
  • Rank 127,237 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Blitz is a document-oriented database for Python that is backend-agnostic. It comes with a flat-file database for JSON documents and provides MongoDB-like querying capabilities.

Blitz-DB

Build Status PyPI Code Issues 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.

Go To Main Documentation

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!

Changelog

  • 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)

  • @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':1L})

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

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':1L})
#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!)

More Repositories

1

gitboard

An intuitve Kanban board for your Github issues, built with React.js. https://adewes.github.io/gitboard
JavaScript
187
star
2

instant-feedback

A Flask application that allows you to add inline feedback elements to any website and collect user feedback on-the-fly. Built with Bootstrap, jQuery, font-awesome and MongoDB.
JavaScript
66
star
3

have-i-been-bloomed

A Bloom filter & Golang server for checking passwords against the "Have I Been Pwned 2.0" password database.
Go
50
star
4

fdtd-ml

FDTD simulation scripts & related tools for machine learning of inverse object representations
Python
37
star
5

battle-stations

Create a status page that uses the Github Issues API & AJAX to show real-time information about service incidents
JavaScript
33
star
6

machine-learning-chinese

Material for my tutorial on machine-learning of Chinese (characters, texts, speech)
Jupyter Notebook
17
star
7

chrome-extension-behavior-analysis

Analyzes the behavior of Chrome extensions via Selenium + Webdriver.
Python
14
star
8

pyview

pyview contains all reusable and generic classes and functions that I used in my qubit data acquisition setup during my PhD thesis.
Python
11
star
9

superconductor

A tool to simulate superconducting circuits, comparable to SPICE.
C++
9
star
10

pdf-printer

A Python + PyQt script that generates PDFs from HTML templates
Python
9
star
11

python-qubit-setup

All scripts for controlling the instruments and acquiring data in our qubit setup.
C++
8
star
12

phd-thesis-physics

My PhD thesis on Experimental Quantum Computing: "Demonstrating Quantum Speed-Up with a 2-Transmon Quantum Processor". The measurement data is too big for the repository, but I can provide access via FTP or Dropbox. The Python code that I've used for controlling my experiments can be found in the "qubit-setup" and "pyview" repositories.
Python
8
star
13

zilpzalp

Privatsphäre-freundliche Kontaktnachverfolgung mit personenbezogenen Daten. Privacy friendly contact tracing with personal data. (Archiviert)
SCSS
7
star
14

epidemic

A simple cohort-based epidemic simulator.
JavaScript
5
star
15

docker-map-reduce-example

A small Docker-based map/reduce example that I prepared for the Europython
Python
5
star
16

type-annotations-in-the-wild

Scripts and data for my analysis of the usage of type annotations in the wild
Jupyter Notebook
5
star
17

tracey

A classy line-by-line profiler for Python code.
CSS
3
star
18

openwrt-cpp-example

An up-to-date (as of 2017) example for a C++ program running on OpenWRT 15.05
Makefile
2
star
19

sozialfunk

Sozialfunk is a Twitter-based social news aggregation, micro-engagement application. It is built using Python, Django, Celery, MongoDB, Tweepy, jQuery & Twitter Bootstrap.
CSS
2
star
20

timetracker

A simple time tracking utility written in Python: Currently it tracks active window under X as well as keyboard and mouse events and logs them to a JSON file.
Python
2
star
21

predpol

Predictive Policing: Algorithm Notes
Jupyter Notebook
1
star
22

32c3

Python code for my presentation at 32c3
Jupyter Notebook
1
star
23

osm-parser

A small Python tool for extracting street information from OSM data
Python
1
star
24

parsejoy

A radpid protoyping parser generator tool: Define and parse grammars without compiling a single line of code.
C++
1
star
25

github-api-scapers

Scripts to retrieve user & repository data from Github using the official Github API. Useful for data mining and research projects.
Python
1
star