swh.web.common.identifiers module

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

Returns the SoftWare Heritage persistent IDentifier for a swh object based on:

  • the object type

  • the object id

  • the SWHID 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 SWHIDs


the SWHID of the object


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

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

Bases: dict

parsed SWHID with context

swhid_parsed: swh.model.swhids.QualifiedSWHID

URL to browse object according to SWHID context

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

Try to resolve a SoftWare Heritage persistent IDentifier into an url for browsing the targeted object.

  • swhid – a SoftWare Heritage persistent IDentifier

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


  • swhid_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_swhid(swhid: str) swh.model.swhids.QualifiedSWHID[source]

Check if a SWHID is valid and return it parsed.


swhid – a SoftWare Heritage persistent IDentifier.


BadInputExc – if the provided SWHID can not be parsed.


A parsed SWHID.

swh.web.common.identifiers.group_swhids(swhids: Iterable[swh.model.swhids.QualifiedSWHID]) Dict[str, List[bytes]][source]

Groups many SoftWare Heritage persistent IDentifiers into a dictionary depending on their type.


swhids – an iterable of SoftWare Heritage persistent IDentifier objects


keys: object types values: object hashes

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 SWHIDs of 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 SWHIDs info