dratio.models.File#

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

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

__init__(code: str, client: Client, **kwargs)#

Initializes the object with the provided code and client instance.

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

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

  • **kwargs – Additional keyword arguments used to initialize the metadata information.

Notes

This method does not perform any request to the database. The metadata information is initialized after is required.

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.

get_download_url()

URL used to download the file (str, read-only).

keys()

Returns the keys of the metadata dictionary.

save()

Saves the object's metadata to the database.

to_geopandas()

Downloads the dataset as a geopandas geodataframe.

to_pandas()

Downloads the dataset as a pandas dataframe.

Attributes

dataset

Dataset of the file (str, read-only).

end_time

End time of the file (str, read-only).

filetype

Filetype of the file (e.g. parquet, geoparquet, etc) (str, read-only).

metadata

Retrieves the metadata associated with the object.

size

Size of the file in bytes (int, read-only).

start_time

Start time of the file (str, read-only).

updated_at

Date when the file was last updated (str, read-only).

version

Version of the file (str, read-only).

property dataset: str | None#

Dataset of the file (str, 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 end_time: str | None#

End time of the file (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:
property filetype: str | None#

Filetype of the file (e.g. parquet, geoparquet, etc) (str, read-only).

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.

get_download_url() str#

URL used to download the file (str, read-only).

Notes

Each time this method is called, a new access url is requested to download the file. The URLs are only valid for a short period of time. If you need to download the same data file at different times, you must request a new url by calling this method.

keys() List[str]#

Returns the keys of the metadata dictionary.

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.

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 size: int | None#

Size of the file in bytes (int, read-only).

property start_time: str | None#

Start time of the file (str, read-only).

to_geopandas() gpd.GeoDataFrame#

Downloads the dataset as a geopandas geodataframe.

Returns:

GeoDataFrame with the dataset.

Return type:

geopandas.GeoDataFrame

Notes

This method requires the geopandas library to be installed.

Raises:
  • ImportError. – If the geopandas library is not installed. You can install it using pip install dratio[geo].

  • requests.exceptions.RequestException. – If the request fails due to an HTTP or Conection Error.

to_pandas() pd.DataFrame#

Downloads the dataset as a pandas dataframe.

Returns:

Dataframe with the dataset.

Return type:

pandas.DataFrame

Raises:

requests.exceptions.RequestException. – If the request fails due to an HTTP or Conection Error.

property updated_at: str | None#

Date when the file was last updated (str, read-only).

property version: str | None#

Version of the file (str, read-only).