Package: efidgy
efidgyPython bindings to efidgy services.OverviewEnvironmentEnvironment in terms of efidgy package is a set of settings to work with efidgy backend.
Theese settings includescustomer codeandaccess tokenthat will be used to communicate with backend.Unit SystemIf you will not set the unit system directly, efidgy will use current user settings:console.efidgy.com/profileAnyway, it is a good practice to define the unit system in your code:efidgy.env=efidgy.env.override(unit_system=efidgy.models.UnitSystem.IMPERIAL,)Credentialsefidgy.env is initialized with settings fetched from the shell environment. The following environment variables are used:EFIDGY_ACCESS_TOKEN -- You can get one atconsole.efidgy.com/profile/companyEFIDGY_CUSTOMER_CODE -- Seeconsole.efidgy.com/profile/tokensYou can always override code and/or token with the code like this:efidgy.env=efidgy.env.override(code='hardcoded customer code',)API documentationFind out more at:efidgy.com/docsSample usageexportEFIDGY_CUSTOMER_CODE=code# https://console.efidgy.com/profile/companyexportEFIDGY_ACCESS_TOKEN=token# https://console.efidgy.com/profile/tokensSync APIimportdatetimeimportefidgydefcreate_project():project=efidgy.models.Project.service.create(name='Demo',currency='USD',project_type=efidgy.models.ProjectTypeCode.IDD_OR,shared_mode=efidgy.models.SharedMode.PRIVATE,)store_address='6133 Broadway Terr., Oakland, CA 94618, USA'lat,lon=efidgy.tools.geocode(store_address)store=efidgy.models.idd_or.Store.service.create(project=project,address=store_address,lat=lat,lon=lon,name='Delivery Inc.',open_time=datetime.time(8,0),close_time=datetime.time(18,0),)efidgy.models.idd_or.Vehicle.service.create(project=project,store=store,name='Gary Bailey',fuel_consumption=11.76,fuel_price=3.25,salary_per_duration=21,duration_limit=datetime.timedelta(hours=9),)order_address='1 Downey Pl, Oakland, CA 94610, USA'lat,lon=efidgy.tools.geocode(order_address)efidgy.models.idd_or.Order.service.create(project=project,store=store,name='#00001',address=order_address,lat=lat,lon=lon,ready_time=datetime.time(8,0),delivery_time_from=datetime.time(12,0),delivery_time_to=datetime.time(16,0),load_duration=datetime.timedelta(minutes=1),unload_duration=datetime.timedelta(minutes=5),items=1,volume=3.53,weight=22.05,)returnprojectdefsolve(project):project.computate()solutions=efidgy.models.Solution.service.all(project=project,)ifnotsolutions:returnNonereturnsolutions[0]defreport(project,solution):print('Total Cost:{cost:.2f}{currency}'.format(cost=solution.cost,currency=project.currency.symbol,))vehicles=efidgy.models.idd_or.Vehicle.service.all(project=project,solution=solution,)forvehicleinvehicles:print('{vehicle}Schedule'.format(vehicle=vehicle.name,))ifvehicle.routeisnotNone:arr=vehicle.route.start_timeforscheduleinvehicle.route.schedule:dep=schedule.departure_timeprint('{at}\t{arr}\t{dep}'.format(at=schedule.start_point.name,arr=arr,dep=dep,))arr=schedule.arrival_timeifvehicle.route.schedule:print('{at}\t{arr}\t{dep}'.format(at=vehicle.route.schedule[-1].end_point.name,arr=vehicle.route.schedule[-1].arrival_time,dep='',))defmain():project=create_project()solution=solve(project)ifsolution:report(project,solution)if__name__=='__main__':main()OutputTotal Cost: 12.51$
Gary Bailey Schedule
Delivery Inc.   15:45:00        15:46:00
#00001          15:55:00        16:00:00
Delivery Inc.   16:09:00Async APIimportdatetimeimportasyncioimportefidgy.asyncapiasefidgyasyncdefcreate_project():project=awaitefidgy.models.Project.service.create(name='Demo',currency='USD',project_type=efidgy.models.ProjectTypeCode.IDD_OR,shared_mode=efidgy.models.SharedMode.PRIVATE,)store_address='6133 Broadway Terr., Oakland, CA 94618, USA'lat,lon=awaitefidgy.tools.geocode(store_address)store=awaitefidgy.models.idd_or.Store.service.create(project=project,address=store_address,lat=lat,lon=lon,name='Delivery Inc.',open_time=datetime.time(8,0),close_time=datetime.time(18,0),)awaitefidgy.models.idd_or.Vehicle.service.create(project=project,store=store,name='Gary Bailey',fuel_consumption=11.76,fuel_price=3.25,salary_per_duration=21,duration_limit=datetime.timedelta(hours=9),)order_address='1 Downey Pl, Oakland, CA 94610, USA'lat,lon=awaitefidgy.tools.geocode(order_address)awaitefidgy.models.idd_or.Order.service.create(project=project,store=store,name='#00001',address=order_address,lat=lat,lon=lon,ready_time=datetime.time(8,0),delivery_time_from=datetime.time(12,0),delivery_time_to=datetime.time(16,0),load_duration=datetime.timedelta(minutes=1),unload_duration=datetime.timedelta(minutes=5),items=1,volume=3.53,weight=22.05,)returnprojectasyncdefsolve(project):awaitproject.computate()solutions=awaitefidgy.models.Solution.service.all(project=project,)ifnotsolutions:returnNonereturnsolutions[0]asyncdefreport(project,solution):print('Total Cost:{cost:.2f}{currency}'.format(cost=solution.cost,currency=project.currency.symbol,))vehicles=awaitefidgy.models.idd_or.Vehicle.service.all(project=project,solution=solution,)forvehicleinvehicles:print('{vehicle}Schedule'.format(vehicle=vehicle.name,))ifvehicle.routeisnotNone:arr=vehicle.route.start_timeforscheduleinvehicle.route.schedule:dep=schedule.departure_timeprint('{at}\t{arr}\t{dep}'.format(at=schedule.start_point.name,arr=arr,dep=dep,))arr=schedule.arrival_timeifvehicle.route.schedule:print('{at}\t{arr}\t{dep}'.format(at=vehicle.route.schedule[-1].end_point.name,arr=vehicle.route.schedule[-1].arrival_time,dep='',))asyncdefmain():project=awaitcreate_project()solution=awaitsolve(project)ifsolution:awaitreport(project,solution)if__name__=='__main__':asyncio.run(main())OutputTotal Cost: 12.51$
Gary Bailey Schedule
Delivery Inc.   15:45:00        15:46:00
#00001          15:55:00        16:00:00
Delivery Inc.   16:09:00