Documentation for stdnet 0.8.2. For development docs, go here.

API

High Level Functions

getdb

stdnet.getdb(backend=None, **kwargs)

get a BackendDataServer.

getcache

stdnet.getcache(backend=None, **kwargs)

Similar to getdb(), it creates a CacheServer.

Interfaces

Backend data server

class stdnet.BackendDataServer(name=None, address=None, charset=None, namespace='', **params)

Generic interface for a backend database. It should not be initialised directly, instead, the getdb() function should be used.

Parameters:
  • name – name of database, such as redis, mongo, etc..
  • address – network address of database server.
  • namespace – optional namespace for keys.
  • params – dictionary of configuration parameters.

ATTRIBUTES

name

name of database

connection_string

The connection string for this backend. By calling getdb() with this value, one obtain a BackendDataServer connected to the same database as this instance.

client

The client handler for the backend database.

Query

The BackendQuery class for this backend.

default_manager

The default model Manager for this backend. If not provided, the stdnet.odm.Manager is used. Default None.

basekey(meta, *args)

Calculate the key to access model data.

Parameters:
  • meta – a stdnet.odm.Metaclass.
  • args – optional list of strings to prepend to the basekey.
Return type:

a native string

disconnect()

Disconnect the connection.

make_objects(meta, data, related_fields=None)

Generator of stdnet.odm.StdModel instances with data from database.

Parameters:
  • meta – instance of model stdnet.odm.Metaclass.
  • data – iterator over instances data.
structure(instance, client=None)

Create a backend stdnet.odm.Structure handler.

Parameters:
async()

Returns an asynchronous BackendDataServer with same connection_string. Asynchronous hadlers must be implemented by users.

setup_model(meta)

Invoked when registering a model with a backend. This is a chance to perform model specific operation in the server. For example, mongo db ensure indices are created.

clean(meta)

Remove temporary keys for a model

ping()

Ping the server

instance_keys(obj)

Return a list of database keys used by instance obj

auto_id_to_python(value)

Return a proper python value for the auto id.

setup_connection(address)

Callback during initialization. Implementation should override this function for customizing their handling of connection parameters. It must return a instance of the backend handler.

execute_session(session, callback)

Execute a stdnet.odm.Session in the backend server.

model_keys(meta)

Return a list of database keys used by model model

as_cache()

Return a CacheServer handle for this backend.

flush(meta=None)

Flush the database or drop all instances of a model/collection

publish(channel, message)

Publish a message to a channel. The backend must support pub/sub paradigm. For information check the Publish/Subscribe application.

subscriber(**kwargs)

Create a Subscriber able to subscribe to channels. For information check the Publish/Subscribe application.

Cache Server

class stdnet.CacheServer

A key-value store server for storing and retrieving values at keys.

set(key, value, timeout=None)

Set value at key with timeout.

get(key, default=None)

Fetch the value at key.

Backend Structure

class stdnet.BackendStructure(instance, backend, client)

Interface for stdnet.odm.Structure backends.

instance

The stdnet.odm.Structure which this backend represents.

backend

The BackendDataServer

client

The client of the BackendDataServer

Asynchronous Components

Asynchronous binding for stdnet.

Backend Query

class stdnet.utils.async.BackendQuery(queryelem, timeout=0, **kwargs)

Asynchronous query interface class which implements the database queries specified by stdnet.odm.Query.

queryelem

The stdnet.odm.QueryElement to process.

executed

flag indicating if the query has been executed in the backend server

cache

Cached results.

items(*args, **kwargs)

This function does the actual fetching of data from the backend server matching this Query. This method is usually not called directly, instead use the all() method or alternatively slice the query in the same way you can slice a list or iterate over the query.

Table Of Contents

Previous topic

Backend Servers

Next topic

Redis

This Page