How to Start SequoiaDB

Basic Operation

Data Model

Database Management








Release Note


  • Content
  • Comments
  • History

Python Development Foundation

This section introduces how to use Python to run the SequoiaDB. Fisrt, to install SequoiaDB, please refer to the Installation of SequoiaDB Server section.

This doc introduces how to use the Python Driver's APIs to develop SequoiaDB database programs. The following samples are not the complete code in order to be clear and simple. for more, please refer to online Python API

Database Manipulations

  • Database Connecting

    connect.py shows how to connect to the database. The file should import client and const modules inside the pysequoiadb, and the error module inside SequoiaDBError class.

    import pysequoiadb
    from pysequoiadb import client
    from pysequoiadb import const
    from pysequoiadb.error import SequoiaDBError
    # connect to local db, using default args value.
    # host= 'localhost', port= 11810, user= '', password= ''
       db = client()
    except DBBaseError, e:
       del db
    # if no error occurs, connect to specified server successfully
    print 'Connect success'
    # Need to release client whether it connected db server successfully or not
    del db

    In Linux, directly run python to interpret and run connect.py.


    In the above sample, the port 11810 the local database connects to is the service port of a coord node; it uses null for user name and password. The users need to configure the parameters according to their own situations. For example, modify db = client() of the above code into db = client('',11810). The correct user name and password are required when the database already has a user, otherwise the connection will fail.

  • Create collection space and collection

    The following sample create a collection space named "foo" and a collection named "bar". The page size of the collection in the collection space is 16k. The page size can be chosen accordingly. The CURD (create, retrieve, update, and delete) operations can be done after the collection is created.

    # connect to a database
       db = client()
    except SDBBaseError, e:
    # success to connect to db
    cs_name = 'foo'
       cs = db.create_collection_space(cs_name, 16384) except SDBBaseError, e:
    # success to create collection space
    cl_name = 'bar'
       cs = cs.create_collection(cl_name)
    except SDBBaseError, e:
  • Insert data

    # firstly, create a object to be inserted named idct.
    record = {"name":"Tom", "age":24}
    # then insert this object dict into the collection.
    oid = cl.insert ( record ) ;

    record is the data to be inserted. dict object will be transformed into bson to insert into the collection. oid is a bson-structured objected to be returned after the data is inserted.

  • Query
    # query all the records, put the result into the cursor, and print each record in the cursor.
       cr = cl.query()
       while True:
             record = cr.next()
          except SDBEndOfCursor:
          except SDBBaseError, e:

    Query operation needs a cursor object to store all the query results in the local. This sample uses the next API of the cursor operation which gets a record from the query result set. This sample only uses the default index without setting query condition, selecting condition, filtering condition, sorting condition.

  • Index
    index_name = "index_name"
    # firest create a dict object includes all the information of the index to be created.
    idx = { 'name':1, 'age':-1 }
    # create a index that uses "name" as the ascending key and "age" as the descending key.
    cl.create_index ( idx, index_name, FALSE, FALSE ) ;

    Create an index that uses "name" as the ascending key and "age" as the descending key in the collection object named collection

  • Update

    # create a BSONObj object which includes the updating rules.
    rule = {"$set":{ "age":19}}
    # print out the updating rules.
    print rule
    # update the records.
    cl.update( rule )

    In the collection object collection update records. Example is not specified in the data matching rules, so this example will update the collection of all the.

Cluster Manipulations

  • Replica Group Manipulations

    Replica group manipulations include creating replica groups (client client::creat_replica_group), getting the replica group instances (client::get_replica_group_by_name and client:: get_replica_group_by_id), start all the nodes of the replica group (replicagroup::start), stop all the nodes in the replica group(replicagroup::stop), etc.

    The following code is a sample of replica group manipulation. The real application includes error detection, etc.
    # define a new map object without any configuring options.
    config = {}
    # create a new catalog replica group first.
    db.create_cata_replica_group ( HOST_NAME, SERVICE_NAME, CATALOG_GROUP_PATH , None)
    # create a data replica group.
    rg = db.create_replica_group ( REPLICA_GROUP_NAME)
    # create a new data node.
    rg.create_node ( HOST_NAME1, SERVICE_NAME1, DATABASE_PATH1, config )
    # start the replica group
    rg.start ()
  • Data Node Manipulation

    Data node manipulation includes creating data node (sdbReplicaGroup::createNode), get the master data node (sdbReplicaGroup::getMaster), get the slave data node (sdbReplicaGroup::getSlave), start data node (sdbNode::start), stop data node (sdb::Stop), etc.

    The following code is a sample of data node manipulation. The real application includes error detection, etc.
    # get the master data node.
    master = rg.get_master() ;
    # get the slave data node.
    slave = rg.get_slave() ;
please login to comment.
Latest Comment
  • 2015-03-14

About Us

SequoiaDB is a financial-level distributed database vendor and is the first Chinese database listed in Gartner’s Magic Quadrant OPDBMS report. SequoiaDB has recently released version 3.0.
SequoiaDB is now penetrating the vertical sector Financial Industry quickly and had more than 50 banking clients and hundreds of enterprise customers in industries including government, telecommunication, Internet and IoT.

Tower R, No.8 North Star East Road, Chaoyang District, Beijing,China
Tower A, No.22 Qinglan Street, Panyu District, Guangzhou,China
Tsing Hua Tech Park, Nanshan District, Shenzhen,China