API Documentation



This module adds DataManagers for Atramhasis. These are service layer objects that abstract all interactions with the database away from the views.

class atramhasis.data.datamanagers.ConceptSchemeManager(session)[source]

A DataManager for ConceptSchemes <skosprovider_sqlalchemy.models.ConceptScheme>.

find(conceptscheme_id, query)[source]

Find concepts and collections in this concept scheme.

  • conceptscheme_id – a concepscheme id
  • query – A python dictionary containing query parameters.

A list of skosprovider_sqlalchemy.models.Thing instances.

Parameters:conceptscheme_id – a concepscheme id
Returns:the concepscheme for the given id

Get all concepts and collections in this concept scheme.

Parameters:conceptscheme_id – a concepscheme id
Returns:A list of skosprovider_sqlalchemy.models.Thing instances.
Parameters:conceptscheme_id – a concepscheme id
Returns:all collections for the scheme_tree
Parameters:conceptscheme_id – a concepscheme id
Returns:all concepts for the scheme_tree
class atramhasis.data.datamanagers.DataManager(session)[source]

A DataManager abstracts all interactions with the database for a certain model.

class atramhasis.data.datamanagers.LanguagesManager(session)[source]

A DataManager for Languages <skosprovider_sqlalchemy.models.Language>.

Parameters:language – the language to delete
Returns:list of all languages
get_all_sorted(sort_coll, sort_desc)[source]
  • sort_coll – sort on this column
  • sort_desc – descending or not

sorted list of languages

Parameters:language – language to save
Returns:saved language
class atramhasis.data.datamanagers.SkosManager(session)[source]

A DataManager for Concepts and Collections <skosprovider_sqlalchemy.models.Thing>.

Parameters:thing – the thing to delete
Parameters:list_type – a specific list type
Returns:all results for the specific list type
get_thing(concept_id, conceptscheme_id)[source]
  • concept_id – a concept id
  • conceptscheme_id – a conceptscheme id

the selected thing (Concept or Collection)

Parameters:thing – thing to save
Returns:saved thing

Produce a descending ORDER BY clause element.


from sqlalchemy import desc

stmt = select([users_table]).order_by(desc(users_table.c.name))

will produce SQL as:

SELECT id, name FROM user ORDER BY name DESC

The desc() function is a standalone version of the ColumnElement.desc() method available on all SQL expressions, e.g.:

stmt = select([users_table]).order_by(users_table.c.name.desc())
Parameters:column – A ColumnElement (e.g. scalar SQL expression) with which to apply the desc() operation.

See also






Module that sets up the datamanagers and the database connections.


Generate a datamanager with a database session and register a cleanup handler.

Parameters:request (pyramid.request.Request) – The request this db session will be tied to.
Returns:A dictionary containing different datamanagers.

Set up SQLAlchemy.

Parameters:config (pyramid.config.Configurator) – Pyramid configuration.


Module containing errors generated by Atramhasis.

exception atramhasis.errors.ConceptNotFoundException(c_id)[source]

A Concept or Collection could not be found.

exception atramhasis.errors.ConceptSchemeNotFoundException(scheme_id)[source]

A ConceptScheme could not be found.

exception atramhasis.errors.DbNotFoundException(value='No database found, please check your application setup')[source]

Atramhasis could not find a database.

exception atramhasis.errors.LanguageNotFoundException(scheme_id)[source]

A Language could not be found.

exception atramhasis.errors.SkosRegistryNotFoundException(value='No SKOS registry found, please check your application setup')[source]

Atramhasis could not find a SKOS registry.

exception atramhasis.errors.ValidationError(value, errors)[source]

Some data that was validated is invalid.


Module containing mapping functions used by Atramhasis.

atramhasis.mappers.map_concept(concept, concept_json, skos_manager)[source]

Map a concept from json to the database.

  • concept (skosprovider_sqlalchemy.models.Thing) – A concept or collection as known to the database.
  • concept_json (dict) – A dict representing the json sent to our REST service.
  • skos_manager – A skos_manager to acces db operations

The skosprovider_sqlalchemy.models.Thing enhanced with the information from the json object.


Thid module is used when blocking operations on a certain Concept or Collection that might be used in external applications.

class atramhasis.protected_resources.ProtectedResourceEvent(uri)[source]

Event triggered when calling a protected operation on a resource

exception atramhasis.protected_resources.ProtectedResourceException(value, referenced_in)[source]

raise this exception when the resource is still used somewhere

referenced_in should contain locations where the resource is still referenced


use this decorator to prevent an operation from being executed when the related resource is still in use


Module containing utility functions used by Atramhasis.


Map a skosprovider_sqlalchemy.models.Thing to a skosprovider.skos.Concept or a skosprovider.skos.Collection, depending on the type.

Parameters:thing (skosprovider_sqlalchemy.models.Thing) – Thing to map.
Return type:Concept or Collection.

aspect oriented way to check if provider is internal when calling the decorated function

Parameters:fn – the decorated function
Returns:around advice
Raises pyramid.httpexceptions.HTTPMethodNotAllowed:
 when provider is not internal


Module that validates incoming JSON.

atramhasis.validators.broader_hierarchy_build(skos_manager, conceptscheme_id, broader, broader_hierarchy)[source]

Builds a list of all the broader concepts of a list of concepts.

atramhasis.validators.broader_hierarchy_rule(errors, node_location, skos_manager, conceptscheme_id, cstruct)[source]

Checks that the broader concepts of a concepts are not alreadt narrower concepts of that concept.

atramhasis.validators.collection_members_unique_rule(errors, node_location, members)[source]

Checks that a collection has no duplicate members.

atramhasis.validators.collection_type_rule(errors, node_location, skos_manager, conceptscheme_id, members)[source]

Checks that the targets of member_of are collections and not concepts.

atramhasis.validators.concept_exists_andnot_different_conceptscheme_rule(errors, node_location, skos_manager, conceptscheme_id, members)[source]

Checks that the members of a collection actually exist and are within the same conceptscheme.

atramhasis.validators.concept_matches_rule(errors, node_location, matches, concept_type)[source]

Checks that only concepts have matches.

atramhasis.validators.concept_matches_unique_rule(errors, node_location, matches)[source]

Checks that a concept has not duplicate matches.

This means that a concept can only have one match (no matter what the type) with another concept. We don’t allow eg. a concept that has both a broadMatch and a relatedMatch with the same concept.

atramhasis.validators.concept_relations_rule(errors, node_location, relations, concept_type)[source]

Checks that only concepts have narrower, broader and related relations.

atramhasis.validators.concept_schema_validator(node, cstruct)[source]

This validator validates an incoming concept or collection

This validator will run a list of rules against the concept or collection to see that there are no validation rules being broken.

  • node (colander.SchemaNode) – The schema that’s being used while validating.
  • cstruct – The concept or collection being validated.
atramhasis.validators.concept_type_rule(errors, node_location, skos_manager, conceptscheme_id, items)[source]

Checks that the targets of narrower, broader and related are concepts and not collections.

atramhasis.validators.label_lang_rule(errors, node, languages_manager, labels)[source]

Checks that languages of a label are valid.

Checks that they are valid IANA language tags. If the language tag was not already present in the database, it adds them.

atramhasis.validators.label_type_rule(errors, node, skos_manager, labels)[source]

Checks that a label has the correct type.

atramhasis.validators.languagetag_checkduplicate(node, language_tag, languages_manager, errors)[source]

Check that a languagetag isn’t duplicated.

atramhasis.validators.languagetag_isvalid_rule(node, language_tag, errors)[source]

Check that a languagetag is a valid IANA language tag.

atramhasis.validators.languagetag_validator(node, cstruct)[source]

This validator validates a languagetag.

The validator will check if a tag is a valid IANA language tag. The the validator is informed that this should be a new language tag, it will also check if the tag doesn’t already exist.

  • node (colander.SchemaNode) – The schema that’s being used while validating.
  • cstruct – The value being validated.
atramhasis.validators.max_preflabels_rule(errors, node, labels)[source]

Checks that there’s only one prefLabel for a certain language.

atramhasis.validators.members_hierarchy_rule(errors, node_location, skos_manager, conceptscheme_id, cstruct)[source]

Checks that a collection does not have members that are in themselves already “parents” of that collection.

atramhasis.validators.members_only_in_collection_rule(errors, node, concept_type, members)[source]

Checks that only collections have members.

atramhasis.validators.min_labels_rule(errors, node, cstruct)[source]

Checks that a label or collection always has a least one label.

atramhasis.validators.narrower_hierarchy_build(skos_manager, conceptscheme_id, narrower, narrower_hierarchy)[source]

Builds a list of all the narrower concepts of a list of concepts.

atramhasis.validators.narrower_hierarchy_rule(errors, node_location, skos_manager, conceptscheme_id, cstruct)[source]

Checks that the narrower concepts of a concept are not already broader concepts of that concept.

atramhasis.validators.subordinate_arrays_hierarchy_rule(errors, node_location, skos_manager, conceptscheme_id, cstruct)[source]

Checks that the subordinate arrays of a concept are not themselves parents of that concept.

atramhasis.validators.subordinate_arrays_only_in_concept_rule(errors, node, concept_type, subordinate_arrays)[source]

Checks that only a concept has subordinate arrays.

atramhasis.validators.subordinate_arrays_type_rule(errors, node_location, skos_manager, conceptscheme_id, subordinate_arrays)[source]

Checks that subordinate arrays are always collections.

atramhasis.validators.superordinates_hierarchy_rule(errors, node_location, skos_manager, conceptscheme_id, cstruct)[source]

Checks that the superordinate concepts of a collection are not themselves members of that collection.

atramhasis.validators.superordinates_only_in_concept_rule(errors, node, concept_type, superordinates)[source]

Checks that only collections have superordinates.

atramhasis.validators.superordinates_type_rule(errors, node_location, skos_manager, conceptscheme_id, superordinates)[source]

Checks that superordinates are always concepts.



class atramhasis.views.views.AtramhasisAdminView(request)[source]

This object groups HTML views part of the admin user interface.

class atramhasis.views.views.AtramhasisListView(request)[source]

This object groups list views part for the user interface.

class atramhasis.views.views.AtramhasisView(request)[source]

This object groups HTML views part of the public user interface.


This view displays the concept details

Parameters:request – A pyramid.request.Request

This view displays conceptscheme details.

Parameters:request – A pyramid.request.Request

This view displays a list of available conceptschemes.

Parameters:request – A pyramid.request.Request

This view returns the favicon when requested from the web root.

Parameters:request – A pyramid.request.Request

This view displays the homepage.

Parameters:request – A pyramid.request.Request

This view displays the search results

Parameters:request – A pyramid.request.Request

This view will set a language cookie

Parameters:request – A pyramid.request.Request


Module containing views related to the REST service.

class atramhasis.views.crud.AtramhasisCrud(context, request)[source]

This object groups CRUD REST views part of the private user interface.


Get an existing concept

Raises atramhasis.errors.ConceptNotFoundException:
 If the concept can’t be found


Module containing error views.

atramhasis.views.exception_views.data_integrity(exc, request)[source]

View invoked when IntegrityError was raised.

atramhasis.views.exception_views.failed(exc, request)[source]

View invoked when bad data was submitted to Atramhasis.

atramhasis.views.exception_views.failed_not_found(exc, request)[source]

View invoked when a resource could not be found.

atramhasis.views.exception_views.failed_skos(exc, request)[source]

View invoked when Atramhasis can’t find a SKOS registry.

atramhasis.views.exception_views.failed_validation(exc, request)[source]

View invoked when bad data was submitted to Atramhasis.

atramhasis.views.exception_views.protected(exc, request)[source]

when a protected operation is called on a resource that is still referenced

atramhasis.views.exception_views.provider_unavailable(exc, request)[source]

View invoked when ProviderUnavailableException was raised.