Git Product home page Git Product logo

cpy-leveldb's Introduction

cpy-leveldb: Python bindings for LevelDB using leveldb c api
(http://code.google.com/p/leveldb/)
author: Fu Haiping ([email protected])

1. Build Instructions
---------------------

First of all, you need to build the included snappy and  leveldb library.

1.1 Build Snappy
-----------------
$ cd snappy
$ ./configure && make && make install

1.2 Build LevelDB
-----------------
$ cd leveldb
$ make 

1.3 Then, build the extension itself
------------------------------------
$ python setup.py build


2. Example Usage
----------------

>>> import leveldb
>>> db = leveldb.LevelDB("/tmp/leveldb")
>>> db.Put("1", "111")
>>> db.Put("2", "222")
>>> db.Put("3", "333")
>>> db.Get("1")
'111'
>>> db.Get("3")
'333'
>>> db.Get("2")
'222'
>>> batch = leveldb.WriteBatch()
>>> for i in xrange(20):
...     batch.Put(str(i), "hello world %i" % i)
... 
>>> db.Get("2")
'222'
>>> db.Get("5")
''
>>> db.Write(batch)
>>> db.Get("5")
'hello world 5'
>>> db.Get("2")
'hello world 2'
>>> iter = leveldb.Iterator(db)
Iterator_init executed.
>>> iter.First()
>>> iter.Key()
'0'
>>> iter.Value()
'hello world 0'
>>> iter.Last()
>>> iter.Key()
'9'
>>> iter.Value()
'hello world 9'
>>> iter.First()
>>> iter.Next()
>>> iter.Key()
'1'
>>> iter.Next()
>>> iter.Key()
'10'
>>> iter.Next()
>>> iter.Key()
'11'
>>> iter.Value()
'hello world 11'
>>> db.Put("1", "111")
>>> db.Put("2", "222")
>>> db.Put("3", "333")
>>> db.Get("1")
'111'
>>> snap = leveldb.Snapshot(db)
Snapshot_init executed.
>>> db.Delete("1")
>>> db.Get("1")
''
>>> snap.Set()
>>> db.Get("1")
'111'
>>> snap.Reset()
>>> db.Get("1")
''
>>> snap.Release()

cpy-leveldb's People

Contributors

forhappy avatar carlopires 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.