unicat
package, reading/traversing/propertiesfrom unicat import Unicat
from config import PROJECT_GID, SECRET_API_KEY, LOCAL_ASSET_FOLDER
# please use the keyring module in .config to store/retrieve the SECRET_API_KEY
unicat = Unicat("https://unicat.app", PROJECT_GID, SECRET_API_KEY, LOCAL_ASSET_FOLDER)
if not unicat.connect():
raise Exception("Invalid connection settings")
unicat.connect() -> bool
unicat.sync() -> True
unicat.get_record(gid: str, *, force: bool) -> UnicatRecord | None
unicat.get_records(gids: list[str], *, force: bool) -> list[UnicatRecord]
unicat.get_root_record() -> UnicatRecord
unicat.get_asset(gid: str, *, force: bool) -> UnicatAsset | None
unicat.get_asset_by_pathname(pathname: str) -> UnicatAsset | None
unicat.get_assets(gids: list[str], *, force: bool) -> list[UnicatAsset]
unicat.get_assets_by_pathname(pathnames: list[str], *, force: bool) -> dict[str, UnicatAsset]
unicat.get_root_asset() -> UnicatAsset
unicat.get_definition(gid: str) -> UnicatDefinition | None
unicat.get_definitions(gids: list[str]) -> list[UnicatDefinition]
unicat.get_definition_by_name(name: str) -> UnicatDefinition | None
unicat.get_definitions_by_name(names: list[str]) -> dict[str, UnicatDefinition]
unicat.get_class(gid: str) -> UnicatClass | None
unicat.get_classes(gids: list[str]) -> list[UnicatClass]
unicat.get_class_by_name(name: str) -> UnicatClass | None
unicat.get_classes_by_name(names: list[str]) -> dict[str, UnicatClass]
unicat.get_field(gid: str) -> UnicatField | None
unicat.get_fields(gids: list[str]) -> list[UnicatField]
unicat.get_field_by_name(name: str) -> UnicatField | None
unicat.get_fields_by_name(names: list[str]) -> dict[str, UnicatField]
unicat.get_query(gid: str) -> UnicatQuery | None
unicat.get_queries(gids: list[str]) -> list[UnicatQuery]
unicat.get_record_query_by_name(name: str) -> UnicatQuery | None
unicat.get_record_queries_by_name(names: list[str]) -> dict[str, UnicatQuery]
unicat.get_asset_query_by_name(name: str) -> UnicatQuery | None
unicat.get_asset_queries_by_name(names: list[str]) -> dict[str, UnicatQuery]
unicat.get_schema_query_by_name(name: str) -> UnicatQuery | None
unicat.get_schema_queries_by_name(names: list[str]) -> dict[str, UnicatQuery]
unicat.walk_record_children(parent_record: UnicatRecord, channel: gid, ordering: gid) -> Iterator[UnicatRecord]
unicat.walk_record_tree(channel: gid, ordering: gid) -> Iterator[UnicatRecord]
unicat.walk_record_query(language: str, query: UnicatQuery, *, limit: int) -> Iterator[tuple[int, UnicatRecord]]
unicat.walk_asset_children(parent_asset: UnicatAsset) -> Iterator[UnicatAsset]
unicat.walk_asset_tree() -> Iterator[UnicatAsset]
unicat.walk_asset_query(language: str, query: UnicatQuery, *, limit: int) -> Iterator[tuple[int, UnicatAsset]]
unicat.walk_definitions() -> Iterator[UnicatDefinition]
unicat.walk_classes() -> Iterator[UnicatClass]
unicat.walk_fields() -> Iterator[UnicatField]
unicat.walk_schema_query(language: str, query: UnicatQuery, *, limit: int) -> Iterator[tuple[int, UnicatQuery]]
unicat.walk_queries() -> Iterator[UnicatQuery]
unicat.project: UnicatProject
UnicatProject
properties & methodsproject.gid: gid
project.name: str
project.owner: UnicatUser
project.icon: str # used to construct /media url
project.status: str
project.languages: list[str]
project.default_language: str
project.channels: dict[str, gid]
project.default_channel: gid
project.channel_name(key: gid) -> str
project.orderings: dict[str, gid]
project.default_ordering: gid
project.ordering_name(key: gid) -> str
project.fieldlists: dict[str, gid]
project.default_fieldlist: gid
project.fieldlist_name(key: gid) -> str
project.backups: list[UnicatProjectBackup]
project.get_backup(version: int) -> UnicatProjectBackup | None
project.members: list[UnicatProjectMember]
UnicatUser
properties & methodsuser.gid: gid
user.username: str
user.name: str
user.avatar: str # used to construct /media url
UnicatProjectMember
properties & methodsprojectmember.project: UnicatProject
projectmember.user: UnicatUser
projectmember.status: str
projectmember.roles: list[str]
projectmember.options: dict
projectmember.key: str
UnicatProjectBackup
properties & methodsbackup.version: int
backup.name: str
backup.created_by: str
backup.timestamp: timestamp # 1610635123.351925
UnicatDefinition
properties & methodsdefinition.gid: gid
definition.original: UnicatDefinition | None
definition.name: str
definition.label: dict[str, str] # key is language
definition.classes: list[UnicatClass]
definition.classes_as_gids: list[gid]
definition.fields: list[UnicatField]
definition.fields_as_gids: list[gid]
definition.titlefield: UnicatField
definition.fieldlists: dict[str, list[UnicatField]] # key is fieldlist key
definition.layout: UnicatLayout
definition.childdefinitions: list[UnicatDefinition]
definition.is_base: bool
definition.is_new: bool
definition.is_extended: bool
definition.is_working_copy: bool
definition.is_committed: bool
definition.all_fields: list[UnicatField]
definition.base_classes: list[UnicatClass]
definition.base_fields: list[UnicatField]
definition.all_base_fields: list[UnicatField]
definition.extended_classes: list[UnicatClass]
definition.extended_fields: list[UnicatField]
definition.all_extended_fields: list[UnicatField]
definition.metadata: dict[str, UnicatMetadataField] # New in v0.7.7
UnicatClass
properties & methodsclass_.gid: gid
class_.original: UnicatClass | None
class_.name: str
class_.label: dict[str, str] # key is language
class_.fields: list[UnicatField]
class_.fields_as_gids: list[gid]
class_.layout: UnicatLayout
class_.is_new: bool
class_.is_working_copy: bool
class_.is_committed: bool
class_.metadata: dict[str, UnicatMetadataField] # New in v0.7.7
UnicatField
properties & methodsfield.gid: gid
field.original: UnicatField | None
field.name: str
field.type: str
field.class_: UnicatClass | None
field.options: dict
field.is_localized: bool
field.is_required: bool
field.label: dict[str, str] # key is language
field.initial: dict[str, str] # key is language
field.unit: str
field.title: dict[str, str] # key is language
field.is_new: bool
field.is_working_copy: bool
field.is_committed: bool
field.metadata: dict[str, UnicatMetadataField] # New in v0.7.7
UnicatLayout
properties & methodslayout.gid: gid
layout.original: UnicatLayout | None
layout.name: str
layout.root: gid
layout.components: dict[gid, dict]
layout.is_new: bool
layout.is_working_copy: bool
UnicatQuery
properties & methodsquery.gid: gid
query.type: str # schema, record, or asset
query.name: str
query.q: str
query.filter: list
UnicatAsset
properties & methodsasset.gid: gid
asset.pathname: str
asset.path: str
asset.name: str
asset.is_file: bool
asset.type: str
asset.childcount: int
asset.status: str
asset.is_deleted: bool
asset.info: dict
asset.transforms: dict[str, dict] | None
asset.default_transform: dict | None
asset.title: dict[str, str] # key is language
asset.description: dict[str, str] # key is language
asset.updated_on: timestamp # 1610635123.351925
asset.publish() -> str # public_url
asset.publish_transformed(transform: UnicatTransform | None) -> str # public_url
asset.download(pathname: str | None) -> False | None | str # local_filepath
asset.download_transformed(transform: UnicatTransform | None, pathname: str | None) -> False | None | str # local_filepath
UnicatRecord
properties & methodsrecord.gid: gid
record.canonical: gid
record.parent: gid
record.backlinks: list[gid]
record.is_link: bool
record.is_deleted: bool
record.treelevel: int
record.path: list[gid]
record.title: dict[str, str] # key is language
record.channels: list[gid] # enabled channels only
record.orderings: dict[gid, int]
record.childcount: int
record.definition: UnicatDefinition
record.fields: dict[str, dict[str, UnicatRecordField]] # key is language, then fieldname
record.validation_report: None | list[dict[str, Any]] # validation result after updates
UnicatRecordField
properties & methodsrecordfield.field: UnicatField
recordfield.value: Any
recordfield.key: None | str
A record field can have a value, a reference (record, asset), or it can be nested for class-fields.
We also support 'list' versions of these.
For textline/textlist fields that have a values option (a selection of values to choose from), the key
property holds the key, and the value
property holds the label (unless value_labels is disabled for that field, then value
holds the key too). The key
is None
in all other cases.
# for values
artnr = record.fields[language]["artnr"] # a recordfield
artnr.value # "CMS 225-945"
artnr.field.label # "Article number"
artnr.field.type # "textline"
# for references
image = record.fields[language]["image"] # both recordfield and asset
image.value # "a0a80c9c-fa1b-4573-ac98-b7b07c81b583"
image.field.label # "Image"
image.pathname # "/products/cms225.eps"
# for class fields
dimensions_interior = record.fields[language]["dimensions_interior"]
# a recordfield and classfield
dimensions_interior.value # {"width__mm": 374, …}
dimensions_interior["width__mm"].value # 374 -- this is a recordfield
# for list values
colors = record.fields[language]["colors"]
colors.value # ["Red", "Blue"]
colors.key # ["r", "b"] -- not named `keys`
colors.field.label # "Colors"
colors[0].value # "Red" -- this is just a string
colors[0].key # "r"
# for list references
images = record.fields[language]["images"]
images.value # ["a0a80c9c-fa1b-4573-ac98-b7b07c81b583", ]
images.field.label # "Images"
images[0] # this is just an asset
images[0].pathname # "/products/cms225.eps"
# for classlist fields
tablespecs = record.fields[language]["tablespecs"]
tablespecs.value # [{"width__mm": 7, …}, …]
tablespecs.field.label # "Table specs"
tablespecs[0] # this is recordfield-like
tablespecs[0]["width__mm"].value # 7
tablespecs[0]["width__mm"].field.label # "Width"
UnicatMetadataField
properties & methodsNew in v0.7.7
metadata_field.name: str
metadata_field.type: str
metadata_field.is_localized: bool
metadata_field.value: None | Any | dict(str, None | Any) # key is language
A metadata field can have a value or a reference (asset, field), and it can be localized. If you need the gid for the reference and don't want it to automatically make an API call, use the underlying metadata_field._value
to get it.
# example field
artnr = unicat.get_field_by_name("artnr")
# for values
meta_align = artnr.metadata["heading.alignment"]
meta_align.name # "heading.alignment"
meta_align.type # "textline"
meta_align.is_localized # False
meta_align.value # "left"
# for localized values
meta_abbr = artnr.metadata["heading.abbreviation"]
meta_abbr.name # "heading.abbreviation"
meta_abbr.type # "textline"
meta_abbr.is_localized # True
meta_abbr.value # {"en": "Artnr", "nl": "Artnr"}
meta_abbr.value["en"] # "Artnr"
# for references
meta_icon = artnr.metadata["heading.icon"]
meta_icon.type # "image"
meta_icon.is_localized # False
meta_icon.value # UnicatAsset | None
meta_icon.value.gid # "a0a80c9c-fa1b-4573-ac98-b7b07c81b583"
meta_icon.value.pathname # "/products/cms225.eps"
meta_related = artnr.metadata["heading.related_field"]
meta_related.type # "fieldpicker"
meta_related.is_localized # False
meta_related.value # UnicatField | None
meta_related.value.gid # "0c9ca0a8-fa1b-4573-ac98-81b583b7b07c"
meta_related.value.name # "EAN"
# for localized references
meta_icon = artnr.metadata["heading.icon"]
meta_icon.type # "image"
meta_icon.is_localized # True
meta_icon.value # {"en": UnicatAsset | None, "nl": UnicatAsset | None} | None
meta_icon.value["en"] # UnicatAsset | None
meta_icon.value["en"].gid # "a0a80c9c-fa1b-4573-ac98-b7b07c81b583"
meta_icon.value["en"].pathname # "/products/cms225.eps"
meta_related = artnr.metadata["heading.related_field"]
meta_related.type # "fieldpicker"
meta_related.is_localized # True
meta_related.value # {"en": UnicatField | None, "nl": UnicatField | None} | None
meta_related.value["en"] # UnicatField | None
meta_related.value["en"].gid # "0c9ca0a8-fa1b-4573-ac98-81b583b7b07c"
meta_related.value["en"].name # "EAN"