@@ -0,0 +1,2837 @@
+#!/usr/bin/env python%0A#%0A# Copyright 2012, Couchbase, Inc.%0A# All Rights Reserved%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22)%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#     http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A#%0Aimport json%0A%0Aimport requests%0A%0A%0Aclass HttpClient(object):%0A%0A    %22%22%22HTTP client with base URL%0A    %22%22%22%0A%0A    def __init__(self, host='127.0.0.1', port=3133):%0A        %22%22%22Initialize base URL%22%22%22%0A        self.base_url = 'http://%7B0%7D:%7B1%7D/'.format(host, port)%0A%0A    def get(self, url, params=None):%0A        %22%22%22Send GET request and return the response object%22%22%22%0A        return requests.get(url=self.base_url + url, params=params)%0A%0A    def post(self, url, data=None, params=None):%0A        %22%22%22Send POST request and return the response object%22%22%22%0A        return requests.post(url=self.base_url + url, data=data, params=params)%0A%0A    def put(self, url):%0A        %22%22%22Send PUT request and return the response object%22%22%22%0A        return requests.put(url=self.base_url + url)%0A%0A    def delete(self, url):%0A        %22%22%22Send DELETE request and return the response object%22%22%22%0A        return requests.delete(url=self.base_url + url)%0A%0A%0Aclass Seriesly(HttpClient):%0A%0A    %22%22%22seriesly connection and database manager%0A    %22%22%22%0A%0A    def create_db(self, dbname):%0A        %22%22%22Create the %60dbname%60 database%22%22%22%0A        self.put(dbname)%0A%0A    def list_dbs(self):%0A        %22%22%22List all known databases on the server%22%22%22%0A        return self.get('_all_dbs').json%0A%0A    def drop_db(self, dbname):%0A        %22%22%22Delete the %60dbname%60 database.%22%22%22%0A        self.delete(dbname)%0A%0A    def __getattr__(self, dbname):%0A        %22%22%22Return an instance of the Database class%22%22%22%0A        return self.__getitem__(dbname)%0A%0A    def __getitem__(self, dbname):%0A        %22%22%22Return an instance of the Database class%22%22%22%0A        return Database(dbname=dbname, connection=self)%0A%0A%0Aclass Database(object):%0A%0A    %22%22%22Datastore%0A    %22%22%22%0A%0A    def __init__(self, dbname, connection):%0A        self.dbname = dbname%0A        self.connection = connection%0A%0A    def append(self, data, timestamp=None):%0A        %22%22%22Store a JSON document with a system-generated or user-specified%0A        timestamps%22%22%22%0A        params = timestamp and %7B'ts': timestamp%7D or %7B%7D%0A        return self.connection.post(self.dbname, json.dumps(data), params).text%0A%0A    def query(self, params=None):%0A        %22%22%22Querying data in seriesly database%22%22%22%0A        params = params or %7B%7D%0A        return self.connection.get(self.dbname + '/_query', params)%0A

add basic client