dratio.models.Feature#

class dratio.models.Feature(code: str, client: Client, **kwargs)#

Feature of a dataset in the database

Parameters:
  • code (str) – Unique identifier of the feature in the database.

  • client (Client) – Client object used to perform requests to the database.

  • **kwargs – Additional keyword arguments used to initialize the metadata information (for internal usage).

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

categories

Returns the categories associated to the object.

column

The column name representing the feature in the dataset (str, read-only).

data_level

Level of the feature (dict, read-only).

data_type

The data type of the feature (e.g., String, Integer, Float) (str, read-only).

dataset

Dataset to which the feature belongs (Dataset, read-only).

description

Returns the description of the object.

feature_type

The type of the feature (e.g., 'Category', 'Identifier') (str, read-only).

last_data

Date of the last observation of the feature (str, read-only).

last_update

Date of the last update of the feature (str, read-only).

license

License to which the feature belongs (License, read-only).

metadata

Retrieves the metadata associated with the object.

name

Returns the name of the object.

next_update

Date of the next update of the feature (str, read-only).

publisher

Publisher to which the feature belongs (Publisher, read-only).

reference

Dataset to which the feature belongs (Dataset, read-only).

reference_feature

Feature to which the feature belongs (Feature, read-only).

scope

Scope of the feature (dict, read-only).

start_data

Date of the first observation of the feature (str, read-only).

update_frequency

Frequency of the updates of the feature (str, read-only).

property categories: List[Category]#

Returns the categories associated to the object.

property column: str | None#

The column name representing the feature in the dataset (str, read-only).

property data_level: Dict[str, str] | None#

Level of the feature (dict, 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).

property dataset: Dataset | None#

Dataset to which the feature belongs (Dataset, read-only).

delete() None#

Deletes the object from the database.

Raises:

requests.exceptions.RequestException – If the request fails.

describe() str#

Returns a string representation of the object’s metadata.

property description: str#

Returns the description of the object.

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:
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.

keys() List[str]#

Returns the keys of the metadata dictionary.

property last_data: str | None#

Date of the last observation of the feature (str, read-only).

property last_update: str | None#

Date of the last update of the feature (str, read-only).

property license: License | None#

License to which the feature belongs (License, read-only).

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 name: str#

Returns the name of the object.

property next_update: str | None#

Date of the next update of the feature (str, read-only).

property publisher: Publisher | None#

Publisher to which the feature belongs (Publisher, read-only).

property reference: Dataset | None#

Dataset to which the feature belongs (Dataset, 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.

property scope: Dict[str, str] | None#

Scope of the feature (dict, read-only).

property start_data: str | None#

Date of the first observation of the feature (str, read-only).

property update_frequency: str | None#

Frequency of the updates of the feature (str, read-only).