Django Cassandra Engine - the Cassandra backend for Django
Project description
django-cassandra-engine is a database wrapper for Django Framework. It uses latest Cqlengine which is currently the best Cassandra CQL 3 Object Mapper for Python.
- License:
2-clause BSD
- Keywords:
django, cassandra, orm, nosql, database, python
- URL (pypi):
Requirements
cassandra
cqlengine
django-nonrel
djangotoolbox
django (1.6 or 1.7)
Features
complete Django integration
working syncdb and flush commands
support for creating/destroying test database
accept all Cqlengine connection options
automatic connection/disconnection handling
support for multiple databases (also relational)
Installation
Recommended installation:
pip install django-cassandra-engine
Usage
Add django-cassandra-engine to INSTALLED_APPS in your settings.py file:
INSTALLED_APPS += ('django_cassandra_engine',)
IMPORTANT: This app should be last on INSTALLED_APPS list.
Also change DATABASES setting:
DATABASES = { 'default': { 'ENGINE': 'django_cassandra_engine', 'NAME': 'db', 'TEST_NAME': 'test_db', 'HOST': 'db1.example.com,db2.example.com', 'OPTIONS': { 'replication': { 'strategy_class': 'SimpleStrategy', 'replication_factor': 1 } } } }
Define some model:
# myapp/models.py import uuid from cqlengine import columns from cqlengine.models import Model class ExampleModel(Model): read_repair_chance = 0.05 # optional - defaults to 0.1 example_id = columns.UUID(primary_key=True, default=uuid.uuid4) example_type = columns.Integer(index=True) created_at = columns.DateTime() description = columns.Text(required=False)
Run ./manage.py syncdb
Done!
Advanced usage
Sometimes you want to use cassandra database along with your RDMS. This is also possible! Just define your DATABASES like here:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), }, 'cassandra': { 'ENGINE': 'django_cassandra_engine', 'NAME': 'db', 'TEST_NAME': 'test_db', 'HOST': '127.0.0.1', 'OPTIONS': { 'replication': { 'strategy_class': 'SimpleStrategy', 'replication_factor': 1 }, 'connection': { 'consistency': ConsistencyLevel.ONE, 'lazy_connect': False, 'retry_connect': False # + All connection options for cassandra.Cluster() } } } }
Then run ./manage.py syncdb for your regular database and ./manage.py syncdb --database cassandra for Cassandra DB.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for django-cassandra-engine-0.0.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a897d421dfbb24b4e9a5ea1e7e02e8e5bf4524cb150ef16b4c808a6b0d1a30c4 |
|
MD5 | 8f1aed78da382b4303e40f0d38d8e779 |
|
BLAKE2b-256 | 522ae8d35a6631664f2ee060775e0ece05d07eca2edc75cecc50e5574e7359a7 |