nrp_cmd.types

Types used inside the nrp client.

 1"""Types used inside the nrp client."""
 2
 3from .base import Model
 4from .info import (
 5    ModelInfo,
 6    ModelInfoContentType,
 7    ModelInfoLinks,
 8    RepositoryInfo,
 9    RepositoryInfoLinks,
10)
11from .records import (
12    FilesEnabled,
13    ParentRecord,
14    Record,
15    RecordId,
16    RecordLinks,
17    RecordList,
18)
19
20__all__ = (
21    "Model", "RepositoryInfo", "RepositoryInfoLinks", "ModelInfo", "ModelInfoContentType", "ModelInfoLinks",
22    "Record", "RecordLinks", "FilesEnabled", "ParentRecord", "RecordList", "RecordId"
23)
class Model:
16class Model:
17    """Base model, which allows getting extra fields via normal dot operator."""
18
19    _extra_data: dict[str, Any]
20
21    def __getattr__(self, item: str) -> Any:  # noqa: ANN401
22        """Get extra fields from the model_extra attribute."""
23        if "_extra_data" not in self.__dict__:
24            self._extra_data: dict[str, Any] = {}
25
26        if item in self._extra_data:
27            return self._extra_data[item]
28        dash_item = item.replace("_", "-")
29        if dash_item in self._extra_data:
30            return self._extra_data[dash_item]
31
32        raise AttributeError(f"{self.__class__.__name__} has no attribute {item}")

Base model, which allows getting extra fields via normal dot operator.

@extend_serialization(allow_extra_data=True)
@define(kw_only=True)
class RepositoryInfo(nrp_cmd.types.Model):
118@extend_serialization(allow_extra_data=True)
119@define(kw_only=True)
120class RepositoryInfo(Model):
121    """Extra info downloaded from nrp-compatible invenio repository."""
122    schema: str
123    """Version of this configuration schema"""
124
125    name: str
126    """The name of the repository"""
127
128    description: str
129    """The description of the repository"""
130
131    version: str
132    """The version of the repository"""
133
134    invenio_version: str
135    """The version of invenio the repository is based on"""
136
137    links: RepositoryInfoLinks
138    """Links to the repository"""
139
140    transfers: list[str] = field(factory=list)
141    """List of supported file transfer protocols"""
142
143    models: dict[str, ModelInfo] = field(factory=dict)
144    """Information about the models in the repository"""
145
146    default_model: str | None = field(default=None)
147    """The default model for the repository. 
148    If set, it is used whenever the model is not specified."""

Extra info downloaded from nrp-compatible invenio repository.

RepositoryInfo( *, schema: str, name: str, description: str, version: str, invenio_version: str, links: RepositoryInfoLinks, transfers: list[str] = NOTHING, models: dict[str, ModelInfo] = NOTHING, default_model: str | None = None)
 2def __init__(self, *, schema, name, description, version, invenio_version, links, transfers=NOTHING, models=NOTHING, default_model=attr_dict['default_model'].default):
 3    self.schema = schema
 4    self.name = name
 5    self.description = description
 6    self.version = version
 7    self.invenio_version = invenio_version
 8    self.links = links
 9    if transfers is not NOTHING:
10        self.transfers = transfers
11    else:
12        self.transfers = __attr_factory_transfers()
13    if models is not NOTHING:
14        self.models = models
15    else:
16        self.models = __attr_factory_models()
17    self.default_model = default_model

Method generated by attrs for class RepositoryInfo.

schema: str

Version of this configuration schema

name: str

The name of the repository

description: str

The description of the repository

version: str

The version of the repository

invenio_version: str

The version of invenio the repository is based on

transfers: list[str]

List of supported file transfer protocols

models: dict[str, ModelInfo]

Information about the models in the repository

default_model: str | None

The default model for the repository. If set, it is used whenever the model is not specified.

@extend_serialization(allow_extra_data=True)
@define(kw_only=True)
class ModelInfo(nrp_cmd.types.Model):
 86@extend_serialization(allow_extra_data=True)
 87@define(kw_only=True)
 88class ModelInfo(Model):
 89    """Information about metadata model within invenio server."""
 90    type: str
 91    """The type of the model"""
 92
 93    schema: str
 94    """The json schema of the model"""
 95
 96    name: str
 97    """The name of the model"""
 98
 99    description: str
100    """The description of the model"""
101
102    version: str
103    """The version of the model"""
104
105    features: list[str]
106    """List of features supported by the model"""
107
108    links: ModelInfoLinks
109    """Links to the model"""
110
111    content_types: list[ModelInfoContentType] = field(factory=list)
112    """List of supported content-types for API serialization"""
113    
114    metadata: bool = field(default=True)
115    """Whether the model contains metadata inside the metadata element."""

Information about metadata model within invenio server.

ModelInfo( *, type: str, schema: str, name: str, description: str, version: str, features: list[str], links: ModelInfoLinks, content_types: list[ModelInfoContentType] = NOTHING, metadata: bool = True)
 2def __init__(self, *, type, schema, name, description, version, features, links, content_types=NOTHING, metadata=attr_dict['metadata'].default):
 3    self.type = type
 4    self.schema = schema
 5    self.name = name
 6    self.description = description
 7    self.version = version
 8    self.features = features
 9    self.links = links
10    if content_types is not NOTHING:
11        self.content_types = content_types
12    else:
13        self.content_types = __attr_factory_content_types()
14    self.metadata = metadata

Method generated by attrs for class ModelInfo.

type: str

The type of the model

schema: str

The json schema of the model

name: str

The name of the model

description: str

The description of the model

version: str

The version of the model

features: list[str]

List of features supported by the model

content_types: list[ModelInfoContentType]

List of supported content-types for API serialization

metadata: bool

Whether the model contains metadata inside the metadata element.

@extend_serialization(allow_extra_data=True)
@define(kw_only=True)
class ModelInfoContentType(nrp_cmd.types.Model):
62@extend_serialization(allow_extra_data=True)
63@define(kw_only=True)
64class ModelInfoContentType(Model):
65    """Acceptable content-types for the model."""
66
67    content_type: str
68    """The content-type accepted by the model"""
69
70    name: str | None = None
71    """The name of the content-type"""
72
73    description: str | None = None
74    """The description of the content-type"""
75
76    schema: URL | None = None
77    """Machine parseable schema for the content-type"""
78    
79    can_export: bool = False
80    """Whether the content-type can be used for exporting records (via Accept header)"""
81    
82    can_deposit: bool = False
83    """Whether the content-type can be used for importing records (via Content-Type header)"""

Acceptable content-types for the model.

ModelInfoContentType( *, content_type: str, name: str | None = None, description: str | None = None, schema: yarl.URL | None = None, can_export: bool = False, can_deposit: bool = False)
2def __init__(self, *, content_type, name=attr_dict['name'].default, description=attr_dict['description'].default, schema=attr_dict['schema'].default, can_export=attr_dict['can_export'].default, can_deposit=attr_dict['can_deposit'].default):
3    self.content_type = content_type
4    self.name = name
5    self.description = description
6    self.schema = schema
7    self.can_export = can_export
8    self.can_deposit = can_deposit

Method generated by attrs for class ModelInfoContentType.

content_type: str

The content-type accepted by the model

name: str | None

The name of the content-type

description: str | None

The description of the content-type

schema: yarl.URL | None

Machine parseable schema for the content-type

can_export: bool

Whether the content-type can be used for exporting records (via Accept header)

can_deposit: bool

Whether the content-type can be used for importing records (via Content-Type header)

@extend_serialization(Rename('files', 'files_'), Omit('_etag', from_unstructure=True), allow_extra_data=True)
@define(kw_only=True)
class Record(nrp_cmd.types.rest.BaseRecord):
55@extend_serialization(Rename("files", "files_"), 
56                      Omit("_etag", from_unstructure=True), 
57                      allow_extra_data=True)
58@define(kw_only=True)
59class Record(BaseRecord):
60    """Record in the repository."""
61
62    links: RecordLinks = field()
63    """Links of the record."""
64
65    files_: Optional[FilesEnabled] = None
66    """Files enabled marker."""
67
68    parent: Optional[ParentRecord] = None
69
70    @property
71    def metadata(self) -> dict:
72        """Return the metadata of the record."""
73        if 'metadata' in self._extra_data:
74            return self._extra_data['metadata']
75        return self._extra_data

Record in the repository.

Record( *, id: RecordIdType, created: datetime.datetime, updated: datetime.datetime, revision_id: Optional[int] = None, links: RecordLinks, files_: Optional[FilesEnabled] = None, parent: Optional[ParentRecord] = None)
 2def __init__(self, *, id, created, updated, revision_id=attr_dict['revision_id'].default, links, files_=attr_dict['files_'].default, parent=attr_dict['parent'].default):
 3    self._etag = attr_dict['_etag'].default
 4    self.id = id
 5    self.created = created
 6    self.updated = updated
 7    self.revision_id = revision_id
 8    self.links = links
 9    self.files_ = files_
10    self.parent = parent

Method generated by attrs for class Record.

files_: Optional[FilesEnabled]

Files enabled marker.

parent: Optional[ParentRecord]
metadata: dict
70    @property
71    def metadata(self) -> dict:
72        """Return the metadata of the record."""
73        if 'metadata' in self._extra_data:
74            return self._extra_data['metadata']
75        return self._extra_data

Return the metadata of the record.

@define(kw_only=True)
class FilesEnabled(nrp_cmd.types.Model):
36@define(kw_only=True)
37class FilesEnabled(Model):
38    """Files enabled marker."""
39
40    enabled: bool

Files enabled marker.

FilesEnabled(*, enabled: bool)
2def __init__(self, *, enabled):
3    self.enabled = enabled

Method generated by attrs for class FilesEnabled.

enabled: bool
@define(kw_only=True)
class ParentRecord(nrp_cmd.types.Model):
43@define(kw_only=True)
44class ParentRecord(Model):
45    """Parent record of the record."""
46
47    communities: dict[str, str]
48    """Communities of the record."""
49
50    workflow: str
51    """Workflow of the record."""

Parent record of the record.

ParentRecord(*, communities: dict[str, str], workflow: str)
2def __init__(self, *, communities, workflow):
3    self.communities = communities
4    self.workflow = workflow

Method generated by attrs for class ParentRecord.

communities: dict[str, str]

Communities of the record.

workflow: str

Workflow of the record.

@extend_serialization(Omit('_etag', from_unstructure=True), allow_extra_data=True)
@define(kw_only=True)
class RecordList(nrp_cmd.types.rest.RESTList[nrp_cmd.types.records.Record]):
78@extend_serialization(Omit("_etag", from_unstructure=True), allow_extra_data=True)
79@define(kw_only=True)
80class RecordList(RESTList[Record]):
81    """List of records."""
82
83    sortBy: Optional[str] = None
84    """Sort by field."""
85    aggregations: Optional[Any] = None
86    """Aggregations."""

List of records.

RecordList( *, links: nrp_cmd.types.rest.RESTPaginationLinks, hits: nrp_cmd.types.rest.RESTHits[T], sortBy: Optional[str] = None, aggregations: Optional[Any] = None)
2def __init__(self, *, links, hits, sortBy=attr_dict['sortBy'].default, aggregations=attr_dict['aggregations'].default):
3    self._etag = attr_dict['_etag'].default
4    self.links = links
5    self.hits = hits
6    self.sortBy = sortBy
7    self.aggregations = aggregations

Method generated by attrs for class RecordList.

sortBy: Optional[str]

Sort by field.

aggregations: Optional[Any]

Aggregations.

RecordId = str | int | yarl.URL