Stores the persistent identifier of a database item.
The ID is split into a prefix and the main identifier.
The prefix identifies an instance of SciCat and the main identifier a dataset.
The two components are merged using a “/”, i.e.
full_id = PID.prefix + "/" + PID.pid
Equivalently, str
can be used to construct the full id:
Constructors
__init__ (*, pid[, prefix])
|
Initialize an instance from individual components. |
parse (x)
|
Build a PID from a string. |
Methods
generate (*[, prefix])
|
Create a new unique PID. |
validate (value)
|
Pydantic validator for PID fields. |
Attributes
pid
|
Main part of the ID. |
prefix
|
Prefix part of the ID if there is one. |
without_prefix
|
Return a new PID with the prefix set to None. |
-
__init__(*, pid, prefix=None)[source]
Initialize an instance from individual components.
- Parameters:
pid (str
) – Main part of the ID which uniquely identifies a dataset.
prefix (str
| None
, default: None
) – Identifies the instance of SciCat.
-
classmethod generate(*, prefix=None)[source]
Create a new unique PID.
Uses UUID4 to generate the ID.
- Parameters:
prefix (str
| None
, default: None
) – If given, the returned PID has this prefix.
- Returns:
PID
– A new PID object.
-
classmethod parse(x)[source]
Build a PID from a string.
The string is split at the first “/” to determine
prefix and main ID.
This means that it only works if the prefix and main ID do
not contain any slashes.
- Parameters:
x (str
| PID
) – String holding an ID with or without prefix.
Or a PID object, in which case a copy is returned.
- Returns:
PID
– A new PID object constructed from x
.
-
property pid: str
Main part of the ID.
-
property prefix: str | None
Prefix part of the ID if there is one.
-
classmethod validate(value)[source]
Pydantic validator for PID fields.
- Return type:
PID
-
property without_prefix: PID
Return a new PID with the prefix set to None.