Scopes¶
Scopes contain datasets, generally from a long-term research project. They serve two primary functions: they assign permissions to view/create datasets to users and groups, and they can enforce data consistency by defining a schema for the attributes of the datasets they contain.
While we recommend managing schemas and user permissions in the DataQruiser app, the qDrive package offers the following functions to work with scopes from Python.
Viewing available scopes¶
To see the scopes available to you:
from qdrive.scopes import get_scopes
scopes = get_scopes()
print(scopes)
# Accessing the scopes
first_scope = scopes[0] # the first scope object in the list
print(first_scope.uuid) # its UUID
print(first_scope.name) # its name
Getting a scope by name or UUID¶
from qdrive.scopes import get_scope
scope = get_scope("my_scope_name")
print(scope.uuid)
print(scope.name)
Setting and getting the default scope¶
When performing operations like searching or creating datasets, the package assumes a default scope is set. You can read or set it with:
from qdrive.scopes import get_scopes, set_default_scope, get_default_scope
scopes = get_scopes()
# Print the name of the current default scope
print(get_default_scope().name)
# Set the default scope by name (option 1)
set_default_scope(scopes[0].name)
# Set the default scope using a scope object (option 2)
set_default_scope(scopes[0])