Skip to content
THIS PROJECT HAS BEEN MERGED INTO THE CQL DRIVER
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
cqlengine
docs removed references to create_missing_keyspace #323 Jan 16, 2015
manifests
modules/cassandra/files
.gitignore
.travis.yml
AUTHORS
CONTRIBUTING.md adding contributor guidelines Jun 3, 2013
LICENSE
MANIFEST.in
Makefile
README.md Include link to canonical project in Readme Apr 24, 2016
RELEASE.txt
Vagrantfile
changelog removed references to create_missing_keyspace #323 Jan 16, 2015
requirements-dev.txt updated dev requirements, skipping static column test in < 2.0 Oct 7, 2014
requirements.txt
setup.py
tox.ini fixing c 1.2 Aug 13, 2014
upgrading.txt

README.md

cqlengine

IMPORTANT!! This package is now deprecated!!

Please use the DataStax native driver, which includes cqlengine as the cassandra.cqlengine module.

Please direct issues to the native driver JIRA

cqlengine build status cqlengine pypi version cqlengine monthly downloads

cqlengine is a Cassandra CQL 3 Object Mapper for Python

Users of versions < 0.16, the default keyspace 'cqlengine' has been removed. Please read this before upgrading: Breaking Changes

Documentation

Report a Bug (Please use this JIRA rather than github issues as it is being retired)

Users Mailing List

Installation

pip install cqlengine

Getting Started on your local machine

#first, define a model
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)

#next, setup the connection to your cassandra server(s) and the default keyspace...
>>> from cqlengine import connection
>>> connection.setup(['127.0.0.1'], "cqlengine")

# or if you're still on cassandra 1.2
>>> connection.setup(['127.0.0.1'], "cqlengine", protocol_version=1)

# create your keyspace.  This is, in general, not what you want in production
# see https://cassandra.apache.org/doc/cql3/CQL.html#createKeyspaceStmt for options
>>> from cqlengine.management import create_keyspace
>>> create_keyspace("cqlengine", "SimpleStrategy", 1)

#...and create your CQL table
>>> from cqlengine.management import sync_table
>>> sync_table(ExampleModel)

#now we can create some rows:
>>> em1 = ExampleModel.create(example_type=0, description="example1", created_at=datetime.now())
>>> em2 = ExampleModel.create(example_type=0, description="example2", created_at=datetime.now())
>>> em3 = ExampleModel.create(example_type=0, description="example3", created_at=datetime.now())
>>> em4 = ExampleModel.create(example_type=0, description="example4", created_at=datetime.now())
>>> em5 = ExampleModel.create(example_type=1, description="example5", created_at=datetime.now())
>>> em6 = ExampleModel.create(example_type=1, description="example6", created_at=datetime.now())
>>> em7 = ExampleModel.create(example_type=1, description="example7", created_at=datetime.now())
>>> em8 = ExampleModel.create(example_type=1, description="example8", created_at=datetime.now())

#and now we can run some queries against our table
>>> ExampleModel.objects.count()
8
>>> q = ExampleModel.objects(example_type=1)
>>> q.count()
4
>>> for instance in q:
>>>     print instance.description
example5
example6
example7
example8

#here we are applying additional filtering to an existing query
#query objects are immutable, so calling filter returns a new
#query object
>>> q2 = q.filter(example_id=em5.example_id)

>>> q2.count()
1
>>> for instance in q2:
>>>     print instance.description
example5

Contributing

If you'd like to contribute to cqlengine, please read the contributor guidelines

Authors

cqlengine was developed primarily by (Blake Eggleston)blakeeggleston and Jon Haddad, with contributions from several others in the community.

You can’t perform that action at this time.