The surf.session
Module¶
-
class
surf.session.
Session
(default_store=None, mapping=None, 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.
Note
The session object behaves like a dict when it comes to managing the registered stores.
-
auto_load
¶ Toggle auto_load (no need to explicitly call load, resources are loaded from the store automatically on creation) on or off. Accepts boolean values.
-
auto_persist
¶ 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
()[source]¶ Close the session.
Note
It is good practice to close the session when it’s no longer needed. Remember: upon closing the session all resources will lose the ability to reference the session thus the store and the mapping.
-
commit
()[source]¶ Commits all changes. In essence the method updates all the dirty registered resources.
-
default_store
¶ The default store of the session.
See default_store_key to see how the default store is selected.
-
default_store_key
¶ 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.
-
get_class
(uri, store=None, classes=None)[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, concept=None, store=None, graph=None, block_auto_load=False, context=None, classes=None)[source]¶ Same as map_type but set the resource from the graph.
-
load_resource
(uri, subject, store=None, data=None, file=None, location=None, format=None, classes=None)[source]¶ Create an instance of the class specified by uri, while subject is the subject of the new resource instance.
The other parameters: data, file, location and format are identical in role to the parameters in
surf.resource.Resource.load_from_source()
.The classes parameter represents the list of base classes of this resource, and is passed further to
surf.session.Session.map_type()
The internal properties are set according to the ones specified by the source.
-