Giter Site home page Giter Site logo

forky-mcforkface / pycassa Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pycassa/pycassa

0.0 0.0 0.0 2.41 MB

Python Thrift driver for Apache Cassandra

Home Page: http://pycassa.github.io/pycassa/

License: Other

Shell 0.09% Python 99.91%

pycassa's Introduction

pycassa

Build Status

pycassa is a Thrift-based python client library for Apache Cassandra

pycassa does not support CQL or Cassandra's native protocol, which are a replacement for the Thrift interface that pycassa is based on. If you are starting a new project, it is highly recommended that you use the newer DataStax python driver instead of pycassa.

pycassa is open source under the MIT license.

Documentation

Documentation can be found here:

http://pycassa.github.com/pycassa/

It includes installation instructions, a tutorial, API documentation, and a change log.

Getting Help

IRC:

Mailing List:

Installation

If pip is available, you can install the lastest pycassa release with:

pip install pycassa

If you want to install from a source checkout, make sure you have Thrift installed, and run setup.py as a superuser:

pip install thrift
python setup.py install

Basic Usage

To get a connection pool, pass a Keyspace and an optional list of servers:

>>> import pycassa
>>> pool = pycassa.ConnectionPool('Keyspace1') # Defaults to connecting to the server at 'localhost:9160'
>>>
>>> # or, we can specify our servers:
>>> pool = pycassa.ConnectionPool('Keyspace1', server_list=['192.168.2.10'])

To use the standard interface, create a ColumnFamily instance.

>>> pool = pycassa.ConnectionPool('Keyspace1')
>>> cf = pycassa.ColumnFamily(pool, 'Standard1')
>>> cf.insert('foo', {'column1': 'val1'})
>>> cf.get('foo')
{'column1': 'val1'}

insert() will also update existing columns:

>>> cf.insert('foo', {'column1': 'val2'})
>>> cf.get('foo')
{'column1': 'val2'}

You may insert multiple columns at once:

>>> cf.insert('bar', {'column1': 'val3', 'column2': 'val4'})
>>> cf.multiget(['foo', 'bar'])
{'foo': {'column1': 'val2'}, 'bar': {'column1': 'val3', 'column2': 'val4'}}
>>> cf.get_count('bar')
2

get_range() returns an iterable. You can use list() to convert it to a list:

>>> list(cf.get_range())
[('bar', {'column1': 'val3', 'column2': 'val4'}), ('foo', {'column1': 'val2'})]
>>> list(cf.get_range(row_count=1))
[('bar', {'column1': 'val3', 'column2': 'val4'})]

You can remove entire keys or just a certain column:

>>> cf.remove('bar', columns=['column1'])
>>> cf.get('bar')
{'column2': 'val4'}
>>> cf.remove('bar')
>>> cf.get('bar')
Traceback (most recent call last):
...
pycassa.NotFoundException: NotFoundException()

See the tutorial for more details.

pycassa's People

Contributors

thobbs avatar jhseu avatar hannosch avatar eevans avatar edevil avatar david-huber avatar sbadia avatar carlopires avatar ketralnis avatar pilate avatar spladug avatar kylemcc avatar bbangert avatar caruccio avatar kurtjx avatar semgrep-bot avatar bjornedstrom avatar gilles avatar wsorenson avatar savinos avatar kaysackey avatar joaquincasares avatar eyalr avatar robotadam avatar amorton avatar dkuebric avatar zachhuff386 avatar umairmufti avatar service-oriented-science avatar sethclong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.