Package: pyloghub
Log-hub Python API libraryTable of ContentsIntroductionPrerequisitesInstallationSetting Up Python EnvironmentInstallingpyloghubPackageConfigurationUsageAvailable FunctionalitiesContact UsLicenseIntroductionThepyloghubpackage provides convinient access to various Log-hub API services for Supply Chain Visualization, Network Design Optimization, and Transport Optimization as well as access to the Log-hub platform data.PrerequisitesPython 3.10 or later recommendedPip (Python package manager)Log-hub API keySupply Chain APPS PRO subscriptionInstallationSetting Up Python EnvironmentRecommended Python VersionPython 3.10 or later is recommended for optimal performance and compatibility.Optional: Setting Up a Virtual EnvironmentA virtual environment allows you to manage Python packages for different projects separately.Create a Virtual Environment:Windows:python-mvenvloghub_envmacOS/Linux:python3-mvenvloghub_envActivate the Virtual Environment:Windows:.\loghub_env\Scripts\activatemacOS/Linux:sourceloghub_env/bin/activateDeactivate withdeactivatewhen done.InstallingpyloghubPackageWithin the environment, install the package using:pipinstallpyloghubConfigurationObtaining an API KeySign up or log in atLog-hub Account Integration.Obtain your API key.Setting Up Your EnvironmentSecurely store your API key for use in your Python scripts or as an environment variable.UsageSample Code: Reverse Distance CalculationThis example demonstrates using the Reverse Distance Calculation feature:Import Functions:frompyloghub.distance_calculationimportreverse_distance_calculation,reverse_distance_calculation_sample_dataLoad Sample Data:sample_data=reverse_distance_calculation_sample_data()geocode_data_df=sample_data['geocode_data']parameters=sample_data['parameters']Perform Calculation:reverse_distance_result_df=reverse_distance_calculation(geocode_data_df,parameters,'YOUR_API_KEY')Replace'YOUR_API_KEY'with your actual Log-hub API key.View Results:print(reverse_distance_result_df)Available FunctionalitiesOverviewpyloghuboffers a suite of functionalities to enhance your supply chain management processes. Below is a quick guide to the available features and sample usage for each.GeocodingForward GeocodingConvert addresses to geographic coordinates.frompyloghub.geocodingimportforward_geocoding,forward_geocoding_sample_datasample_data=forward_geocoding_sample_data()addresses_df=sample_data['addresses']forward_geocoding_result_df=forward_geocoding(addresses_df,api_key)Reverse GeocodingConvert geographic coordinates to addresses.frompyloghub.geocodingimportreverse_geocoding,reverse_geocoding_sample_datasample_data=reverse_geocoding_sample_data()geocodes_df=sample_data['geocodes']reverse_geocoding_result_df=reverse_geocoding(geocodes_df,api_key)Distance CalculationForward Distance CalculationCalculate distances based on address data.frompyloghub.distance_calculationimportforward_distance_calculation,forward_distance_calculation_sample_datasample_data=forward_distance_calculation_sample_data()address_data_df=sample_data['address_data']parameters=sample_data['parameters']forward_distance_calculation_result_df=forward_distance_calculation(address_data_df,parameters,api_key)Reverse Distance CalculationCalculate distances based on geocode data.frompyloghub.distance_calculationimportreverse_distance_calculation,reverse_distance_calculation_sample_datasample_data=reverse_distance_calculation_sample_data()geocode_data_df=sample_data['geocode_data']parameters=sample_data['parameters']reverse_center_of_gravity_result_df=reverse_distance_calculation(geocode_data_df,parameters,api_key)Center of GravityForward Center of GravityDetermine optimal facility locations based on addresses.frompyloghub.center_of_gravityimportforward_center_of_gravity,forward_center_of_gravity_sample_datasample_data=forward_center_of_gravity_sample_data()addresses_df=sample_data['addresses']parameters=sample_data['parameters']assigned_addresses_df,centers_df=forward_center_of_gravity(addresses_df,parameters,api_key)Reverse Center of GravityDetermine optimal facility locations based on coordinates.frompyloghub.center_of_gravityimportreverse_center_of_gravity,reverse_center_of_gravity_sample_datasample_data=reverse_center_of_gravity_sample_data()coordinates_df=sample_data['coordinates']parameters=sample_data['parameters']assigned_geocodes_df,centers_df=reverse_center_of_gravity(coordinates_df,parameters,api_key)Transport OptimizationMilkrun Optimization PlusOptimize delivery routes with multiple stops.frompyloghub.milkrun_optimization_plusimportforward_milkrun_optimization_plus,forward_milkrun_optimization_plus_sample_datasample_data=forward_milkrun_optimization_plus_sample_data()depots_df=sample_data['depots']vehicles_df=sample_data['vehicles']jobs_df=sample_data['jobs']timeWindowProfiles_df=sample_data['timeWindowProfiles']breaks_df=sample_data['breaks']parameters=sample_data['parameters']route_overview_df,route_details_df,external_orders_df=forward_milkrun_optimization_plus(depots_df,vehicles_df,jobs_df,timeWindowProfiles_df,breaks_df,parameters,api_key)Transport Optimization PlusOptimize transport routes for shipments.frompyloghub.transport_optimization_plusimportforward_transport_optimization_plus,forward_transport_optimization_plus_sample_datasample_data=forward_transport_optimization_plus_sample_data()vehicles_df=sample_data['vehicles']shipments_df=sample_data['shipments']timeWindowProfiles_df=sample_data['timeWindowProfiles']breaks_df=sample_data['breaks']parameters=sample_data['parameters']route_overview_df,route_details_df,external_orders_df=forward_transport_optimization_plus(vehicles_df,shipments_df,timeWindowProfiles_df,breaks_df,parameters,api_key)Shipment AnalyzerAnalyze and optimize shipment costs and operations.frompyloghub.shipment_analyzerimportforward_shipment_analyzer,forward_shipment_analyzer_sample_datasample_data=forward_shipment_analyzer_sample_data()shipments_df=sample_data['shipments']transport_costs_adjustments_df=sample_data['transportCostAdjustments']consolidation_df=sample_data['consolidation']surcharges_df=sample_data['surcharges']parameters=sample_data['parameters']shipments_analysis_df,transports_analysis_df=forward_shipment_analyzer(shipments_df,transport_costs_adjustments_df,consolidation_df,surcharges_df,parameters,api_key)For the Milkrun Optimization, Transport Optimization as well as the Shipment Analyzer service there is also the reverse version available.Working with Log-hub TablesTo read or update a table, you need a table link from a table in the Log-hub platform. Therefore, please navigate in a workspace with an existing dataset and go to the table you would like to read or update. Click on the "three dots" and click on "Table Link". Then copy the corresponding table link. If no table exists create a dataset and a new table via the GUI.Reading Data from a TableThe read_table function simplifies the process of fetching and formatting data from a specific table on the Log-hub platform into a pandas DataFrame. This function ensures that the data types in the DataFrame match those in the Log-hub table, leveraging metadata from the table for precise formatting.frompyloghub.datasetimportread_tableimportpandasaspd# Replace with actual table link, email, and API keytable_link="https://production.supply-chain-apps.log-hub.com/api/v1/datasets/.../tables/.../rows"email="your_email@example.com"api_key="your_api_key"# Read data from tabledataframe=read_table(table_link,email,api_key)# Check the DataFrameifdataframeisnotNone:print(dataframe.head())else:print("Failed to read data from the table.")Updating Data in a TableThe update_table function is designed for uploading data from a local pandas DataFrame to a specific table on the Log-hub platform. It requires the table link, the DataFrame, metadata describing the table structure (optional). If no metadata are provided, the datatypes are automatically extracted from the pandas dataframe.frompyloghub.datasetimportupdate_tableimportpandasaspd# Replace with actual credentials and linktable_link="https://production.supply-chain-apps.log-hub.com/api/v1/datasets/.../tables/.../rows"email="your_email@example.com"api_key="your_api_key"# Example DataFramedataframe=pd.DataFrame({'ColumnA':['Value1','Value2'],'ColumnB':[123,456]})# Metadata for the tablemetadata={'table_name':'YourTableName',# Optional, defaults to 'Table 01' if not provided'columns':[{'name':'ColumnA','propertyName':'ColumnA','dataType':'string','format':'General'},{'name':'ColumnB','propertyName':'ColumnB','dataType':'number','format':'General'}# More columns as needed]}# Update tableresponse=update_table(table_link,dataframe,metadata,email,api_key)ifresponseisNone:print("Table updated successfully.")else:print("Failed to update the table.")Contact UsFor any inquiries, assistance, or additional information, feel free to reach out to us at our office or via email.Address:Schwandweg 5,8834 Schindellegi,SwitzerlandEmail:support@log-hub.comAlternatively, for more information and resources, visitLog-hub API Documentation.LicenseDistributed under theMIT License.