dratio.models.Feature#
- class dratio.models.Feature(code: str, client: Client, **kwargs)#
Feature of a dataset in the database
- Parameters:
Examples
Initialize a client object and get a dataset object
>>> from dratio import Client >>> client = Client("You API key")
Obtain the feature by its code
>>> feature = client.get_feature("municipalities__municipality-id") >>> feature Feature('municipalities__municipality-id')
Or obtain it from the dataset features dictionary by column name
>>> dataset = client.get("municipalities") >>> feature = dataset.features.get("municipality_id") >>> feature Feature('municipalities__municipality-id')
Get feature’s attributes
>>> feature.name 'Municipality ID' >>> feature.description 'Municipality code (int format) assigned by the National Statistics Institute...'
Obtain all metadata associated with the feature
>>> feature.metadata {'code': 'municipalities__municipality-id', ...}
- __init__(code: str, client: Client, **kwargs)#
Initializes the object with the provided code and client instance.
Methods
__init__
(code, client, **kwargs)Initializes the object with the provided code and client instance.
delete
()Deletes the object from the database.
describe
()Returns a string representation of the object's metadata.
fetch
([fail_not_found])Updates the metadata dictionary of the object by performing an HTTP request to the server.
from_dict
(metadata)Updates the internal state of the object with the provided metadata.
keys
()Returns the keys of the metadata dictionary.
save
()Saves the object's metadata to the database.
Attributes
Returns the categories associated to the object.
The column name representing the feature in the dataset (str, read-only).
Level of the feature (dict, read-only).
The data type of the feature (e.g., String, Integer, Float) (str, read-only).
Dataset to which the feature belongs (Dataset, read-only).
Returns the description of the object.
The type of the feature (e.g., 'Category', 'Identifier') (str, read-only).
Date of the last observation of the feature (str, read-only).
Date of the last update of the feature (str, read-only).
License to which the feature belongs (License, read-only).
Retrieves the metadata associated with the object.
Returns the name of the object.
Date of the next update of the feature (str, read-only).
Publisher to which the feature belongs (Publisher, read-only).
Dataset to which the feature belongs (Dataset, read-only).
Feature to which the feature belongs (Feature, read-only).
Scope of the feature (dict, read-only).
Date of the first observation of the feature (str, read-only).
Frequency of the updates of the feature (str, read-only).
- property column: str | None#
The column name representing the feature in the dataset (str, read-only).
- property data_type: Literal['String', 'Integer', 'Float', 'Text', 'Interval', 'Date', 'Datetime', 'Geometry'] | None#
The data type of the feature (e.g., String, Integer, Float) (str, read-only).
- delete() None #
Deletes the object from the database.
- Raises:
requests.exceptions.RequestException – If the request fails.
- property feature_type: Literal['Category', 'Geometry', 'Statistic', 'Interval', 'Identifier', 'Number', 'Percentage'] | None#
The type of the feature (e.g., ‘Category’, ‘Identifier’) (str, read-only).
- fetch(fail_not_found: bool = True) DatabaseResource #
Updates the metadata dictionary of the object by performing an HTTP request to the server.
- Returns:
self (DatabaseResource) – The object itself.
fail_not_found (bool, default True) – Whether to raise an exception if the object is not found in the database.
Notes
This method modifies the object’s internal state.
- Raises:
requests.exceptions.RequestException – If the request fails.
ObjectNotFound – If the object is not found in the database.
- from_dict(metadata)#
Updates the internal state of the object with the provided metadata.
- Parameters:
metadata (dict) – Dictionary containing the metadata of the object.
- Returns:
self – The object itself.
- Return type:
DatabaseResource
Notes
This method modifies the object’s internal state.
- property metadata: Dict[str, Any]#
Retrieves the metadata associated with the object.
Notes
The first time this property is accessed, a request is made to the server to fetch the metadata. Subsequent accesses return the previously loaded information. To update the metadata, create a new instance of the object.
- property publisher: Publisher | None#
Publisher to which the feature belongs (Publisher, read-only).
- property reference_feature: Feature | None#
Feature to which the feature belongs (Feature, read-only).
- save() DatabaseResource #
Saves the object’s metadata to the database.
- Returns:
self – The object itself.
- Return type:
DatabaseResource
- Raises:
requests.exceptions.RequestException – If the request fails.