swh.web.common.identifiers module

swh.web.common.identifiers.get_swh_persistent_id(object_type: str, object_id: str, scheme_version: int = 1, metadata: swh.web.common.typing.SWHIDContext = {}) → str[source]

Returns the persistent identifier for a swh object based on:

  • the object type

  • the object id

  • the swh identifiers scheme version

  • object_type – the swh object type (content/directory/release/revision/snapshot)

  • object_id – the swh object id (hexadecimal representation of its hash value)

  • scheme_version – the scheme version of the swh persistent identifiers


the swh object persistent identifier


BadInputExc – if the provided parameters do not enable to generate a valid identifier

class swh.web.common.identifiers.ResolvedPersistentId(**kwargs)[source]

Bases: dict

parsed SWHID with context

swh_id_parsed: PersistentId

URL to browse object according to SWHID context

browse_url: Optional[str]
swh.web.common.identifiers.resolve_swh_persistent_id(swh_id: str, query_params: Optional[Union[Dict[str, Any], django.http.request.QueryDict]] = None)swh.web.common.identifiers.ResolvedPersistentId[source]

Try to resolve a Software Heritage persistent id into an url for browsing the targeted object.

  • swh_id – a Software Heritage persistent identifier

  • query_params – optional dict filled with query parameters to append to the browse url


  • swh_id_parsed: the parsed identifier

  • browse_url: the url for browsing the targeted object

Return type

a dict with the following keys

swh.web.common.identifiers.get_persistent_identifier(persistent_id: str)swh.model.identifiers.PersistentId[source]

Check if a persistent identifier is valid.


persistent_id – A string representing a Software Heritage persistent identifier.

  • BadInputExc – if the provided persistent identifier can

  • not be parsed.


A persistent identifier object.

swh.web.common.identifiers.group_swh_persistent_identifiers(persistent_ids: Iterable[swh.model.identifiers.PersistentId]) → Dict[str, List[bytes]][source]

Groups many Software Heritage persistent identifiers into a dictionary depending on their type.


persistent_ids – an iterable of Software Heritage persistent identifier objects


keys: persistent identifier types values: persistent identifiers id

Return type

A dictionary with

swh.web.common.identifiers.get_swhids_info(swh_objects: Iterable[swh.web.common.typing.SWHObjectInfo], snapshot_context: Optional[swh.web.common.typing.SnapshotContext] = None, extra_context: Optional[Dict[str, Any]] = None) → List[swh.web.common.typing.SWHIDInfo][source]

Returns a list of dict containing info related to persistent identifiers of swh objects.

  • swh_objects – an iterable of dict describing archived objects

  • snapshot_context – optional dict parameter describing the snapshot in which the objects have been found

  • extra_context – optional dict filled with extra contextual info about the objects


a list of dict containing persistent identifiers info