dratio.models.File#
- class dratio.models.File(code: str, client: Client, **kwargs)#
File of a dataset in the database
- Parameters:
- __init__(code: str, client: Client, **kwargs)#
Initializes the object with the provided code and client instance.
- Parameters:
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.
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.
Downloads the dataset as a geopandas geodataframe.
Downloads the dataset as a pandas dataframe.
Attributes
Dataset of the file (str, read-only).
End time of the file (str, read-only).
Filetype of the file (e.g. parquet, geoparquet, etc) (str, read-only).
Retrieves the metadata associated with the object.
Size of the file in bytes (int, read-only).
Start time of the file (str, read-only).
Date when the file was last updated (str, read-only).
Version of the file (str, read-only).
- delete() None #
Deletes the object from the database.
- Raises:
requests.exceptions.RequestException – If the request fails.
- 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.
- 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.
- 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.
- to_geopandas() gpd.GeoDataFrame #
Downloads the dataset as a geopandas geodataframe.
- Returns:
GeoDataFrame with the dataset.
- Return type:
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:
- Raises:
requests.exceptions.RequestException. – If the request fails due to an HTTP or Conection Error.