leaf_engine.io.api ================== .. py:module:: leaf_engine.io.api Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/leaf_engine/io/api/base_caller/index /autoapi/leaf_engine/io/api/caller/index /autoapi/leaf_engine/io/api/crud_caller/index /autoapi/leaf_engine/io/api/crud_openapi/index /autoapi/leaf_engine/io/api/openapi/index /autoapi/leaf_engine/io/api/planning_caller/index /autoapi/leaf_engine/io/api/planning_openapi/index Exceptions ---------- .. autoapisummary:: leaf_engine.io.api.LeafAPIException Classes ------- .. autoapisummary:: leaf_engine.io.api.LeafAPICaller Functions --------- .. autoapisummary:: leaf_engine.io.api.validate_lane leaf_engine.io.api.validate_location leaf_engine.io.api.validate_shipment Package Contents ---------------- .. py:exception:: LeafAPIException Bases: :py:obj:`Exception` Common base class for all non-exit exceptions. .. py:class:: LeafAPICaller(endpoint: Optional[str] = API_ENDPOINT, key: Optional[str] = API_KEY) Makes calls to the analytics API. The API documentation is available at: https://api.leaflogistics.com/analytics/docs. NOTE that using instances of this class in a Jupyter notebook might cause unexpected behavior - always initialize the LeafAPICaller instance in the same notebook cell where you call its methods. .. py:method:: _summarize_responses(path: str, responses: List[LeafAPIResponse]) -> None .. py:method:: check_lane_ids(uuids: List[str], batch_size: int = 1000, verbose: int = 0) -> List[bool] Receives a list of UUIDs and returns an equivalent list of bools indicating if the lane UUID already exists in the database. .. py:method:: check_location_ids(uuids: List[str], batch_size: int = 1000, verbose: int = 0) -> List[bool] Receives a list of UUIDs and returns an equivalent list of bools indicating if the location UUID already exists in the database. .. py:method:: check_raw_shipment_ids(uuids: List[str], batch_size: int = 1000, verbose: int = 0) -> List[bool] Receives a list of UUIDs and returns an equivalent list of bools indicating if the raw shipment UUID already exists in the database. .. py:method:: check_shipment_ids(uuids: List[str], batch_size: int = 1000, verbose: int = 0) -> List[bool] Receives a list of UUIDs and returns an equivalent list of bools indicating if the shipment UUID already exists in the database. .. py:method:: create_batch(batch: dict) -> dict .. py:method:: create_cluster_schema(schema: dict) -> dict .. py:method:: create_dataset(dataset: dict) -> dict .. py:method:: delete_batches(batch_ids: List[str], cascade_delete: bool = False) -> List[LeafAPIResponse] Deletes batches based on batch `id`. If `cascade_delete` is False, only the batch is deleted from the database. If True, shipments, lanes, locations, and datasets that have the same batch date and company id will be deleted. .. py:method:: delete_datasets(dataset_ids: List[str]) -> List[LeafAPIResponse] Deletes datasets based on dataset `id`. .. py:method:: delete_many(records: List[Any], path: str, n_jobs: int = -1, batch_size: int = -1, verbose: int = 0, **kwargs) -> List[LeafAPIResponse] Makes multiple DELETE requests to the analytics API endpoint defined by `path`. Splits up `records` into individual lists based on `batch_size`. If `batch_size` is less than or equal to 0, it will send all records in a single DELETE request. If multiple DELETE calls are made, they are made in parallel using joblib. .. py:method:: delete_one(path: str, data: Union[List, dict], **kwargs) -> LeafAPIResponse Makes a single DELETE request to the analytics API endpoint defined by `path`. Note that the current API endpoints support batching, so in the DELETE call below the json data is passed to the API as a list. If a single dictionary is passed, it is wrapped in a list. :param path: The API path to call. :type path: str :param data: The data to DELETE, either a dict or list of dicts. :type data: Union[List, Dict] :returns: A list of API responses. :rtype: List[LeafAPIResponse] .. py:method:: get(path: str, **kwargs) -> requests.Response .. py:method:: get_batches(batch_id: Optional[str] = None, batch_date: Optional[str] = None, company_id: Optional[int] = None) -> pandas.DataFrame Retrieves batches based on given query parameters. Any kwarg that is not None is used to filter database batches. The batches returned will meet every filter. The date should be in "YYYY-MM-DD" format. .. py:method:: get_cluster_location(company_id: int, zip: Optional[str] = None, city: Optional[str] = None, state: Optional[str] = None, country: Optional[str] = None) -> Optional[dict] Retrieves the most recent cluster for a given location and company. `company_id` is a required argument. Along with `company_id` either `zip` or `city`, `state`, and `country` must be passed. If all are passed, `zip` will take priority. .. py:method:: get_cluster_locations(company_id: int) -> pandas.DataFrame Retrieves all cluster locations for a given company. .. py:method:: get_cluster_schema(company_id: int, name: str) -> dict Returns the most recent cluster schema with `name` for `company_id`. :param company_id: Company ID. :type company_id: int :param name: Cluster schema name. :type name: str :returns: Cluster schema dictionary. :rtype: (dict) .. py:method:: get_cluster_schema_by_id(id: str) -> Optional[dict] Returns cluster schema with `id`. :param id: Cluster schema id. :type id: str :returns: Cluster schema dictionary. :rtype: (dict) .. py:method:: get_datasets(dataset_id: Optional[str] = None, company_id: Optional[str] = None, url: Optional[str] = None, label: Optional[str] = None, mapper: Optional[str] = None, hash: Optional[int] = None) -> pandas.DataFrame Retrieves datasets based on given query parameters. Any kwarg that is not None is used to filter database datasets. The datasets returned will meet every filter. .. py:method:: get_lanes(company_id: int) -> pandas.DataFrame Retrieves all lanes for a given company. .. py:method:: get_locations(company_id: int) -> pandas.DataFrame Retrieves all locations for a given company. .. py:method:: get_point_location(company_id: int, zip: Optional[str] = None, city: Optional[str] = None, state: Optional[str] = None, country: Optional[str] = None) -> Optional[dict] Retrieves the most recent point for a given location and company. `company_id` is a required argument. Along with `company_id` either `zip` or `city`, `state`, and `country` must be passed. If all are passed, `zip` will take priority. .. py:method:: get_point_locations(company_id: int, exclude_record_type: str = 'RFP') -> pandas.DataFrame Retrieves all point locations for a given company. Optionally excludes locations with a given record type. Defaults to excluding RFPs. .. py:method:: get_power_lanes(company_id: int) -> pandas.DataFrame Retrieves all power lanes for a given company. .. py:method:: get_ptp_lanes(company_id: int) -> pandas.DataFrame Retrieves all ptp lanes for a given company. .. py:method:: get_raw_shipments(batch_date: Optional[str] = None, company_id: Optional[int] = None) -> pandas.DataFrame Retrieves raw shipments based on given query parameters. Any kwarg that is not None is used to filter database shipments. The shipments returned will meet every filter. The date should be in "YYYY-MM-DD" format. .. py:method:: get_records(path: str, **kwargs) -> pandas.DataFrame Makes multiple GET requests to the analytics API endpoint defined by `path` to get all pages / all records . :param path: The API path to call. :type path: str :returns: A DataFrame with all records (useful in getting all lane and location records for a company_id, see methods below). :rtype: pd.DataFrame .. py:method:: get_shipments(company_id: int) -> pandas.DataFrame Retrieves all shipments for a given company. .. py:method:: insert_lanes(records: List[dict], batch_size: int = 50, verbose: int = 0) -> List[LeafAPIResponse] .. py:method:: insert_locations(records: List[dict], batch_size: int = 50, verbose: int = 0) -> List[LeafAPIResponse] .. py:method:: insert_raw_shipments(records: List[dict], batch_size: int = 50, verbose: int = 0) -> List[LeafAPIResponse] .. py:method:: insert_records(path: str, records: List[dict], batch_size: int = 50, verbose: int = 0) -> List[LeafAPIResponse] .. py:method:: insert_shipments(records: List[dict], batch_size: int = 50, verbose: int = 0) -> List[LeafAPIResponse] .. py:method:: post(path: str, data: Union[dict, List]) -> LeafAPIResponse .. py:method:: post_many(records: List[Any], path: str, n_jobs: int = -1, batch_size: int = -1, verbose: int = 0) -> List[LeafAPIResponse] Makes multiple POST requests to the analytics API endpoint defined by `path`. Splits up `records` into individual lists based on `batch_size`. If `batch_size` is less than or equal to 0, it will send all records in a single POST request. If multiple POST calls are made, they are made in parallel using joblib. .. py:method:: put(path: str, data: Union[dict, List]) -> LeafAPIResponse .. py:method:: update_cluster_schema(schema: dict) -> dict .. py:attribute:: endpoint .. py:attribute:: key .. py:attribute:: retries .. py:attribute:: session .. py:function:: validate_lane(record) .. py:function:: validate_location(record) .. py:function:: validate_shipment(record)