Fom - API Documentation

fom.session

Combining a db instance with an API.

copyright:2009-2010 Fom Authors.
license:MIT, see LICENSE for more information.
class fom.session.Fluid(base_url='https://fluiddb.fluidinfo.com')

A fluiddb session.

Parameters:
  • base_url – The base FluidDB url to use. Currently, this can only be either the main FluidDB instance, or the sandbox instance.
bind()

Bind this instance of the session to the global object mapper

This is a convenience to allow declaring mapped objects that are bound to this session without requiring passing the session to each created object.

>>> fdb = Fluid()
>>> fdb.bind()
>>> from fom.mapper import Object
>>> o = Object() # this is bound to the fdb instance
login(username, password)

Log in to the connected FluidDB

The login is maintained for the session until logout() is called.

>>> fdb = Fluid()
>>> fdb.login(u'test', u'test')
>>> fdb.users.get(u'aliafshar') # this is now authenticated
Parameters:
  • username – The username to log in with.
  • password – The password to log in with.
logout()

Log out of the FluidDB session

fom.mapping

Object orientated interface into FluidDB

copyright:2010 Fom Authors.
license:MIT, see LICENSE for more information.
class fom.mapping.Namespace(path, fluid=None)

A FluidDB Namespace

api

The associated API instance for this Namespace

It can be used to access lower-level information as required. Read-only.

>>> ns = Namespace(u'fluiddb')
>>> ns.api.get()
<FluidResponse (200, 'application/json', ...>
create(description)

Create this namespace.

Parameters:
  • description – The description of the Namespace
create_namespace(name, description)

Create a child namespace, and return it.

Parameters:
  • name – The name of the Namespace to be created
  • description – The description of the Namespace to be created
create_tag(name, description, indexed)

Create a tag in this namespace, and return it.

Parameters:
  • name – The name of the Tag to be created
  • description – The description of the Tag to be created
  • indexed – Whether the Tag will be indexed
delete()

Delete this namespace.

description

The description of this Namespace.

Setting and getting the value attempts to set/get the description in FluidDB.

namespace(name)

Get a child namespace of this namespace

Parameters:
  • name – The name of the child namespace to get.
namespace_names

The names of the child Namespaces in this Namespace

namespace_paths

The full paths of the child Namespaces in this Namespace

namespaces

The child Namespaces in this Namespace

tag(name)

Get a child tag of this namespace.

Parameters:
  • name – The name of the child Tag to get.
tag_names

The names of the Tags in this Namespace.

tag_paths

The full paths of the Tags in this Namespace

tags

The Tags in this Namespace

class fom.mapping.Object(uid=None, about=None, fluid=None, initial={})

An object

api

The api ObjectApi for this instance.

create(about=None)

Create a new object.

delete(tagpath)

Removes a tag from the object

classmethod filter(query, result_type=None)

Returns a collection of objects that match the supplied query written in the query language described here:

http://doc.fluidinfo.com/fluidDB/queries.html

If result_type is passed the results will be instantiated as a list of result_type otherwise they’ll be instantiations of cls.

get(tagpath)

Get the value of a tag.

get_cached(tagpath)

Get the cached value of a tag.

has(tag)

Check if an object has a tag.

refresh(*tagpaths)

Clears the local cache

save()

Saves those fields that have been updated

set(tagpath, value, valueType=None)

Set the value of a tag.

set_lazy_tag_value(tag_value, value)

Sets the value of the given tag_value instance to be pushed to FluidDB only when save() is called

class fom.mapping.Permissions(api)

A nicer view onto Namespace/Tag/TagValue permissions

class fom.mapping.Policy(policy='open', exceptions=[])

Represents a policy specification for permissions on an action

class fom.mapping.SessionBound(path, fluid=None)

Something with a path that is bound to a database.

path

The path of the item relative to the toplevel.

fluid

The instance of fom.session.Fluid bound to this item.

class fom.mapping.Tag(path, fluid=None)

A FluidDB Tag

api

The associated API instance for this Tag

It can be used to access lower-level information as required. Read-only.

>>> tag = Tag(u'fluiddb/about')
>>> tag.api.get()
<FluidResponse (200, 'application/json', ...>
delete()

Delete this tag

description

The description of a tag.

Setting the value attempts to set the description in the FluidDB.

>>> tag = Tag(u'fluiddb/about')
>>> tag.description
u'A description of what an object is about.'
fom.mapping.path_child(path, child)

Get the named child for a path.

fom.mapping.path_split(path)

Split a path into parent, self

fom.mapping.readonly_tag_value

Descriptor to provide a tag value lookup on an object to simulate a simple attribute.

Parameters:
  • tagpath – The path of the tag to store this value in and read it from
fom.mapping.tag_relation

Descriptor to provide a relation lookup.

An id is actually stored in the database.

fom.mapping.tag_relations

Descriptor to provide a list of relations.

A list of ids are stored in the database

fom.mapping.tag_value

Descriptor to provide a tag value lookup on an object to simulate a simple attribute. With write support.

Parameters:
  • tagpath – The path of the tag to store this value in and read it from
  • content_type – The default MIME-type to be used when PUTting the value
  • cached – Flag to indicate if the value should be cached locally
  • lazy_save – Flag to indicate if the field’s value should be updated when the instance.save() method is called

fom.api

Thin wrapper over the fluiddb restish api.

copyright:2009-2010 Fom Authors.
license:MIT, see LICENSE for more information.
class fom.api.FluidApi(db)

Complete fluiddb api

provides the API toplevels. The API toplevels are each bound to the instance of fom.db.FluidDB, and correspond to FluidDB’s toplevels.

tags

A bound instance of fom.api.TagsApi

namespaces

A bound instance of fom.api.NamespacesApi

users

A bound instance of fom.api.UsersApi

objects

A bound instance of fom.api.ObjectsApi

permissions

A bound instance of fom.api.PermissionsApi

policies

A bound instance of fom.api.PoliciesApi

class fom.api.ApiBase(db)

Base class for an api component.

Stores the db instance as state and uses it to call the required call.

Parameters:
root_path

The root path against which request paths are calculated

db

The FluidDB that this API is bound to.

__call__(method, path=None, *args, **kw)

Make a request against the fluiddb.

The path is relative to this API’s root path, but otherwise parameters are as fom.db.FluidDB.__call__()

class fom.api.AboutObjectApi(about, db)

API component for a single object referenced by its about tag value.

get()

Call GET on an individual object.

class fom.api.AboutObjectTagApi(about, tagpath, db)

API component for a tag on an object referenced by its about tag value.

delete()

Call DELETE on an individual object’s tag.

get()

Call GET on an individual object’s tag.

head()

Call HEAD on an individial object’s tag.

put(value, value_type=None)

Call PUT on an individual object’s tag.

class fom.api.AboutObjectsApi(db)

API Component for the /about toplevel

post(about)

Call POST on the /about toplevel to create a new object.

Parameters:
  • about – The value for the about tag.
class fom.api.ApiBase(db)

Base class for an api component.

Stores the db instance as state and uses it to call the required call.

Parameters:
class fom.api.FluidApi(db)

Complete fluiddb api

provides the API toplevels. The API toplevels are each bound to the instance of fom.db.FluidDB, and correspond to FluidDB’s toplevels.

tags

A bound instance of fom.api.TagsApi

namespaces

A bound instance of fom.api.NamespacesApi

users

A bound instance of fom.api.UsersApi

objects

A bound instance of fom.api.ObjectsApi

permissions

A bound instance of fom.api.PermissionsApi

policies

A bound instance of fom.api.PoliciesApi

class fom.api.ItemPermissionsApi(root_path, path, db)

API component for all individual permissions.

class fom.api.ItemsPermissionsApi(root_path, db)

API component for all groups of permissions for a type of toplevel.

class fom.api.NamespaceApi(path, db)

API Component for a single Namespace.

This is usually returned by using the NamespacesApi[path], or can be created as required for a specific namespace:

>>> from fom.db import FluidDB
>>> db = FluidDB()
>>> ns_api = NamespaceApi('fluiddb', db) # api for the fluiddb namespace
>>> ns_api.get(returnDescription=True)
delete()

Call DELETE on the namespace to delete it.

get(returnDescription=False, returnNamespaces=False, returnTags=False)

Call GET on the namespaces to fetch information about it.

post(name, description)

Call POST on the namespace to create a new child namespace.

put(description)

Call PUT on ther namespace to update its description.

class fom.api.NamespacesApi(db)

API Component for the /namespaces target.

Provides no methods, only access to named namespaces.

class fom.api.ObjectApi(uid, db)

API component for a single object.

get(showAbout=False)

Call GET on an individual object.

class fom.api.ObjectTagApi(uid, tagpath, db)

API component for a tag on an object.

delete()

Call DELETE on an individual object’s tag.

get()

Call GET on an individual object’s tag.

head()

Call HEAD on an individial object’s tag.

put(value, value_type=None)

Call PUT on an individual object’s tag.

class fom.api.ObjectsApi(db)

API Component for the /objects toplevel

get(query)

Call GET on the /objects toplevel

post(about=None)

Call POST on the /objects toplevel to create a new object.

Parameters:
  • about – The value for the about tag. If this is omitted, or

None is passed, no about tag will be set.

class fom.api.PermissionsApi(db)

API Component for /permissions toplevel.

class fom.api.PoliciesApi(db)

API Component for the /policies toplevel.

class fom.api.PolicyApi(username, category, action, db)

API Component for a specific permission

get()

Call get on the Policy.

path

Get the path of this component relative to the toplevel.

put(policy, exceptions)

Call put on the policy.

class fom.api.TagApi(path, db)

API Component for a single tag.

class fom.api.TagsApi(db)

API Component for /tags toplevel.

class fom.api.UserApi(username, db)

API component for a single user.

get()

Return information about the user.

class fom.api.UsersApi(db)

API component for users.

This is a container API that handles getting the path for individual users.

class fom.api.ValuesApi(db)

API Component for the /values toplevel

delete(query, taglist)

Call DELETE on the /values toplevel with a supplied query and list of tags to delete

get(query, taglist)

Call GET on the /values toplevel with a supplied query and list of tags to return.

put(query, values)

Call PUT on the /values toplevel with a supplied query and payload indicating new/updated tag-values.

fom.db

Raw connection and querying.

copyright:2009-2010 Fom Authors.
license:MIT, see LICENSE for more information.
fom.db.BASE_URL

The default FluidDB URL

fom.db.SERIALIZABLE_TYPES

A set of serializable content types

fom.db.ITERABLE_TYPES

A set of iterable types of primitive

fom.db.PRIMITIVE_CONTENT_TYPE

The primitive FluidDB content type

fom.db.DESERIALIZABLE_CONTENT_TYPES

Content types which can be deserialized

class fom.db.FluidDB(base_url='https://fluiddb.fluidinfo.com')

HTTP client.

Could/Should be swapped out for other implementations. Although is generally synchronous.

Parameters:
  • base_url – The base FluidDB url to use. Currently, this can only be either the main FluidDB instance, or the sandbox instance.
__call__(method, path, payload=<object object at 0xb7771ad0>, urlargs=None, content_type=None, is_value=False)

Make a request and return a response.

>>> db = FluidDB()
>>> r = db('GET', '/users/aliafshar')
>>> print r.value
{u'name': u'aliafshar', u'id': u'11e00b96-e346-44e7-af7f-e1a3575ff43e'}
Parameters:
  • method – The HTTP method
  • path – The path to make the request to
  • payload – The body of the request
  • urlargs – URL arguments to be applied to the request
  • content_type – The content type of the payload
  • is_value – A boolean flag to indicate whether the response is from a value request. Value requests are not deserialized unless they are of the primitive content type: application/vnd.fluiddb.value+json even if they are of a deserializable content type such as application/json
class fom.db.FluidResponse(response, content, is_value)

A response to a FluidDB request.

These are generally created by the API, and returned, and there is little use to create them manually.

Parameters:
  • response – An httplib2 response instance, which is a dict with an additional status attribute.
  • content – The body of the HTTP response.
  • is_value – A boolean flag to indicate whether the response is from a value request. Value requests are not deserialized unless they are of the primitive content type: application/vnd.fluiddb.value+json even if they are of a deserializable content type such as application/json
content_type

The content type of the response.

value

The deserialized value of the response body, if it is appropriate for deserialization.

content

The raw content of the response body.

request_id

The request id of the response. This is only available during errors.

error

The error from the response. This is only available during errors.