The surf.session Module

class surf.session.Session(default_store=None, mapping={}, auto_persist=False, auto_load=False)[source]

Bases: object

The Session will manage the rest of the components in SuRF, it also acts as the type factory for surf, the resources will walk the graph in a lazy manner based on the session that they are bound to (the last created session).

Create a new session object that handles the creation of types and instances, also the session binds itself to the Resource objects to allow the Resources to access the data store and perform lazy loading of results.


The session object behaves like a dict when it comes to managing the registered stores.


Toggle auto_load (no need to explicitly call load, resources are loaded from the store automatically on creation) on or off. Accepts boolean values.


Toggle auto_persistence (no need to explicitly call commit, resources are persisted to the store each time a modification occurs) on or off. Accepts boolean values.


Close the session.


It is good practice to close the session when it’s no longer needed. Remember: upon closing session all resources will lose the ability to reference the session thus the store and the mapping.


Commit all the changes, update all the dirty resources.


The default store of the session.

See default_store_key to see how the default store is selected.


The default store key of the session.

If it is set explicitly on session creation it is returned, else the first store key is returned. If no stores are in the session None is returned.


Toggle logging on or off. Accepts boolean values.

get_class(uri, store=None, *classes)[source]

See surf.session.Session.map_type(). The uri parameter can be any of the following:

  • a URIRef

  • a Resource

  • a string of the form
    • a URI
    • a Resource class name eg: SiocPost
    • a namespace_symbol type string eg: sioc_post
get_resource(subject, uri=None, store=None, graph=None, block_auto_load=False, context=None, *classes)[source]

Same as map_type but set the resource from the graph.


The keys that are assigned to the managed stores.

load_resource(uri, subject, store=None, data=None, file=None, location=None, format=None, *classes)[source]

Create a instance of the class specified by uri.

Also set the internal properties according to the ones by the specified source.

map_instance(concept, subject, store=None, classes=[], block_auto_load=False, context=None)[source]

Create a instance of the class specified by uri and classes to be inherited, see map_type for more information.

map_type(uri, store=None, *classes)[source]

Create and return a class based on the uri given.

Also will add the classes to the inheritance list.

Previous topic

The surf.serializer Module

Next topic

The Module

This Page