HuwiseDataset
Object-oriented interface for dataset operations with method chaining support.
Overview
HuwiseDataset is a dataclass that represents a Huwise dataset and provides:
- Fluent interface: Chain method calls for cleaner code
- Dependency injection: Accept custom configuration
- Type safety: Full type hints for all methods
- Lazy operations: Control when changes are published
Usage
Creating Instances
from huwise_utils_py import HuwiseDataset
# From a dataset ID
dataset = HuwiseDataset.from_id("100123")
# With custom configuration
from huwise_utils_py import HuwiseConfig
config = HuwiseConfig(api_key="key", domain="custom.domain.com")
dataset = HuwiseDataset.from_id("100123", config=config)
Reading Metadata
# Basic fields
title = dataset.get_title()
description = dataset.get_description()
keywords = dataset.get_keywords()
language = dataset.get_language()
publisher = dataset.get_publisher()
theme = dataset.get_theme()
license_value = dataset.get_license() # checks internal.license_id, falls back to default.license
# DCAT-AP-CH fields
rights = dataset.get_dcat_ap_ch_rights()
dcat_license = dataset.get_dcat_ap_ch_license()
# DCAT fields
created = dataset.get_created()
issued = dataset.get_issued() # publication date
creator = dataset.get_creator()
contributor = dataset.get_contributor()
contact_name = dataset.get_contact_name()
contact_email = dataset.get_contact_email()
periodicity = dataset.get_accrualperiodicity()
relation = dataset.get_relation()
# Default template fields
modified = dataset.get_modified()
geo_refs = dataset.get_geographic_reference()
# Get all metadata
metadata = dataset.get_metadata()
Updating Metadata
# Single update (publishes automatically)
dataset.set_title("New Title")
# Update without publishing
dataset.set_title("New Title", publish=False)
# Method chaining
dataset.set_title("Title", publish=False) \
.set_description("Description", publish=False) \
.set_keywords(["tag1", "tag2"], publish=False) \
.publish()
# DCAT-AP-CH fields
dataset.set_dcat_ap_ch_rights(
"NonCommercialAllowed-CommercialAllowed-ReferenceRequired",
publish=False,
)
dataset.set_dcat_ap_ch_license("terms_by", publish=False)
# DCAT fields
dataset.set_creator("Data Team", publish=False)
dataset.set_contributor("Open Data Basel-Stadt", publish=False)
dataset.set_contact_name("Data Office", publish=False)
dataset.set_contact_email("data@example.com", publish=False)
dataset.set_issued("2024-06-01", publish=False)
dataset.set_created("2024-06-01T10:00:00Z", publish=False)
dataset.set_accrualperiodicity(
"http://publications.europa.eu/resource/authority/frequency/DAILY",
publish=False,
)
dataset.set_relation("https://example.com/related", publish=False)
# Geographic reference
dataset.set_geographic_reference(["ch_40_12"], publish=False)
# Modified date with companion flags
dataset.set_modified(
"2024-06-01T12:00:00Z",
updates_on_metadata_change=True,
updates_on_data_change=False,
publish=False,
)
dataset.publish()
Dataset Actions
# Publish changes
dataset.publish()
# Unpublish dataset
dataset.unpublish()
# Refresh dataset (re-process)
dataset.refresh()
Method Chaining
All setter methods return self, enabling fluent interfaces:
dataset = HuwiseDataset.from_id("100123")
# Chain all updates, then publish once at the end
dataset.set_title("New Title", publish=False) \
.set_description("Updated description", publish=False) \
.set_keywords(["python", "data", "automation"], publish=False) \
.set_language("en", publish=False) \
.set_publisher("Open Data Basel-Stadt", publish=False) \
.set_theme("environment", publish=False) \
.set_dcat_ap_ch_rights("NonCommercialAllowed-CommercialAllowed-ReferenceRequired", publish=False) \
.set_dcat_ap_ch_license("terms_by", publish=False) \
.set_creator("Data Team", publish=False) \
.set_contact_email("data@example.com", publish=False) \
.set_geographic_reference(["ch_40_12"], publish=False) \
.publish()
This is more efficient than calling each setter with publish=True because it only makes one publish API call instead of six.
API Reference
HuwiseDataset(uid: str, config: HuwiseConfig = HuwiseConfig.from_env())
dataclass
Represents a Huwise dataset with metadata operations.
Provides a fluent interface for reading and modifying dataset metadata. Supports method chaining for convenient batch updates.
| ATTRIBUTE | DESCRIPTION |
|---|---|
uid |
The unique string identifier of the dataset.
TYPE:
|
config |
Optional HuwiseConfig (uses default if not provided).
TYPE:
|
Examples:
Create from a dataset ID and modify with method chaining:
dataset = HuwiseDataset.from_id("100123")
dataset.set_title("New Title", publish=False) .set_description("Description") .publish()
Read metadata:
config: HuwiseConfig = field(default_factory=(HuwiseConfig.from_env))
class-attribute
instance-attribute
from_id(dataset_id: str, config: HuwiseConfig | None = None) -> Self
classmethod
Create a dataset instance from a numeric dataset ID.
| PARAMETER | DESCRIPTION |
|---|---|
dataset_id
|
The numeric identifier of the dataset.
TYPE:
|
config
|
Optional HuwiseConfig instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
HuwiseDataset instance with resolved UID. |
| RAISES | DESCRIPTION |
|---|---|
IndexError
|
If no dataset is found with the given ID. |
Source code in src/huwise_utils_py/dataset.py
get_metadata() -> dict[str, Any]
Retrieve the full metadata of the dataset.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary containing all metadata templates and fields. |
Source code in src/huwise_utils_py/dataset.py
get_title() -> str | None
Retrieve the dataset title.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The dataset title or None if not set. |
get_description() -> str | None
Retrieve the dataset description.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The dataset description or None if not set. |
get_keywords() -> list[str] | None
Retrieve the dataset keywords.
| RETURNS | DESCRIPTION |
|---|---|
list[str] | None
|
List of keywords or None if not set. |
get_language() -> str | None
Retrieve the dataset language.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The language code or None if not set. |
get_publisher() -> str | None
Retrieve the dataset publisher.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The publisher name or None if not set. |
get_theme() -> str | None
Retrieve the dataset theme.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The theme ID or None if not set. |
get_license() -> str | None
Retrieve the dataset license.
Checks internal.license_id first (where the platform stores the
canonical license ID, e.g. "5sylls5"). Falls back to
default.license (human-readable string used by older datasets,
e.g. "CC BY").
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The license identifier/name, or None if neither field is set. |
Source code in src/huwise_utils_py/dataset.py
get_custom_view() -> dict[str, Any] | None
Retrieve the dataset custom view configuration.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any] | None
|
Custom view dictionary or None if not set. |
get_dcat_ap_ch_rights() -> str | None
Retrieve the DCAT-AP-CH rights statement.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The rights statement string (e.g. |
str | None
|
|
str | None
|
or None if not set. |
Source code in src/huwise_utils_py/dataset.py
get_dcat_ap_ch_license() -> str | None
Retrieve the DCAT-AP-CH license code.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The license code (e.g. |
get_created() -> str | None
Retrieve the dataset creation date (dcat.created).
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
ISO datetime string or None if not set. |
get_issued() -> str | None
Retrieve the dataset publication date (dcat.issued).
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
ISO datetime string or None if not set. |
get_creator() -> str | None
Retrieve the dataset creator.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The creator name or None if not set. |
get_contributor() -> str | None
Retrieve the dataset contributor.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The contributor name or None if not set. |
get_contact_name() -> str | None
Retrieve the dataset contact name.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The contact name or None if not set. |
get_contact_email() -> str | None
Retrieve the dataset contact email.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The contact email address or None if not set. |
get_accrualperiodicity() -> str | None
Retrieve the dataset accrual periodicity.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
EU frequency URI string (e.g. |
str | None
|
|
str | None
|
or None if not set. |
Source code in src/huwise_utils_py/dataset.py
get_relation() -> str | None
Retrieve the dataset relation URL.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The relation URL string or None if not set. |
get_modified() -> str | None
Retrieve the dataset last-modified date (default.modified).
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
ISO datetime string or None if not set. |
get_geographic_reference() -> list[str] | None
Retrieve the dataset geographic reference codes.
| RETURNS | DESCRIPTION |
|---|---|
list[str] | None
|
List of geographic reference codes (e.g. |
list[str] | None
|
|
Source code in src/huwise_utils_py/dataset.py
set_title(title: str, *, publish: bool = True) -> Self
Set the dataset title.
| PARAMETER | DESCRIPTION |
|---|---|
title
|
The new title for the dataset.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_description(description: str, *, publish: bool = True) -> Self
Set the dataset description.
| PARAMETER | DESCRIPTION |
|---|---|
description
|
The new description for the dataset.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_keywords(keywords: list[str], *, publish: bool = True) -> Self
Set the dataset keywords.
| PARAMETER | DESCRIPTION |
|---|---|
keywords
|
List of keywords for the dataset.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_language(language: str, *, publish: bool = True) -> Self
Set the dataset language.
| PARAMETER | DESCRIPTION |
|---|---|
language
|
Language code (e.g., "en", "de", "fr").
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_publisher(publisher: str, *, publish: bool = True) -> Self
Set the dataset publisher.
| PARAMETER | DESCRIPTION |
|---|---|
publisher
|
Publisher name.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_theme(theme_id: str, *, publish: bool = True) -> Self
Set the dataset theme.
| PARAMETER | DESCRIPTION |
|---|---|
theme_id
|
Theme identifier.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_license(license_id: str, *, license_name: str | None = None, publish: bool = True) -> Self
Set the dataset license.
Uses per-field PUT endpoints to update default.license_id
(and optionally default.license) without risking overwrites to
other metadata fields. The platform propagates license_id to
internal.license_id automatically.
| PARAMETER | DESCRIPTION |
|---|---|
license_id
|
License identifier (e.g.
TYPE:
|
license_name
|
Optional human-readable name (e.g.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_dcat_ap_ch_rights(rights: str, *, publish: bool = True) -> Self
Set the DCAT-AP-CH rights statement.
| PARAMETER | DESCRIPTION |
|---|---|
rights
|
Rights statement string (e.g.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_dcat_ap_ch_license(license_code: str, *, publish: bool = True) -> Self
Set the DCAT-AP-CH license code.
| PARAMETER | DESCRIPTION |
|---|---|
license_code
|
License code (e.g.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_created(created: str, *, publish: bool = True) -> Self
Set the dataset creation date (dcat.created).
| PARAMETER | DESCRIPTION |
|---|---|
created
|
ISO datetime string (e.g.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_issued(issued: str, *, publish: bool = True) -> Self
Set the dataset publication date (dcat.issued).
| PARAMETER | DESCRIPTION |
|---|---|
issued
|
ISO datetime string (e.g.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_creator(creator: str, *, publish: bool = True) -> Self
Set the dataset creator.
| PARAMETER | DESCRIPTION |
|---|---|
creator
|
Creator name.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_contributor(contributor: str, *, publish: bool = True) -> Self
Set the dataset contributor.
| PARAMETER | DESCRIPTION |
|---|---|
contributor
|
Contributor name.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_contact_name(name: str, *, publish: bool = True) -> Self
Set the dataset contact name.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Contact name.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_contact_email(email: str, *, publish: bool = True) -> Self
Set the dataset contact email.
| PARAMETER | DESCRIPTION |
|---|---|
email
|
Contact email address.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_accrualperiodicity(frequency: str, *, publish: bool = True) -> Self
Set the dataset accrual periodicity.
| PARAMETER | DESCRIPTION |
|---|---|
frequency
|
EU frequency URI string (e.g.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_relation(relation: str, *, publish: bool = True) -> Self
Set the dataset relation URL.
| PARAMETER | DESCRIPTION |
|---|---|
relation
|
Relation URL string.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_geographic_reference(references: list[str], *, publish: bool = True) -> Self
Set the dataset geographic reference codes.
| PARAMETER | DESCRIPTION |
|---|---|
references
|
List of geographic reference codes (e.g.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
set_modified(modified: str, *, updates_on_metadata_change: bool | None = None, updates_on_data_change: bool | None = None, publish: bool = True) -> Self
Set the dataset last-modified date (default.modified).
Uses per-field PUT endpoints so that each field is updated
| PARAMETER | DESCRIPTION |
|---|---|
modified
|
ISO datetime string (e.g.
TYPE:
|
updates_on_metadata_change
|
If given, sets whether the modified date should auto-update when metadata changes.
TYPE:
|
updates_on_data_change
|
If given, sets whether the modified date should auto-update when data changes.
TYPE:
|
publish
|
Whether to publish after updating.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
publish() -> Self
Publish the dataset to make changes visible.
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
Source code in src/huwise_utils_py/dataset.py
unpublish() -> Self
Unpublish the dataset.
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |
refresh() -> Self
Refresh the dataset (re-process data).
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Self for method chaining. |