Package: emsapi
Python Client Library for the EMS APIThis project is a client library for the EMS API that is generated usingAutoRest. It is intended to be a direct mirror of the routes and models exposed by the EMS API. This makes the package suitable for purpose-built projects that want to use the low-level API routes directly with minimal effort.For data science and exploratory use, consider using theemsPypackage instead.Getting StartedInstall via pippipinstallemsapiCreate an API clientIn your code, create an API client object using an endpoint, username, and password:fromemsapiimportemsapiuser="..."password="..."url="https://ems.efoqa.com/api/"client=emsapi.create(user,password,url)Set connection settings (optional)If you need to change any connection settings these will be set on theconfigproperty of the client. This property supports all configuration supported by autorest (see definitionhere)# Add a proxy server for https requestsclient.config.proxies.add("https","https://my-proxy")# Do not verify SSL certificatesclient.config.connection.verify=False# Increase the max retries to 5client.config.retry_policy.max_retries=5Retrieve EMS system idIf the EMS system id is not known, it should be retrieved before any further requests:ems_id=client.find_ems_system_id("ems-server-name")Access routes on the API clientDifferent routes are exposed as members of theclientobject created in the previous step. These routes match the sections in theAPI Explorerdocumentation in the web UI. Most of them need the ems system id (see previous step).# The routes exposed by the client:client.analyticclient.analytic_setclient.assetclient.databaseclient.ems_profileclient.ems_systemclient.navigationclient.parameter_setclient.profileclient.tableauclient.trajectoryclient.transferclient.uploadclient.weatherExamplesHandling errorsCheck for and handle error messages from any routeimportloggingresponse=client.analytic.get_analytic_group_contents(ems_id)ifclient.is_error(response):message=client.get_error_message(response)logging.error(message)Analytic queryQuery a time-series parameter for a flight# List the root analytic group contentsgroups=client.analytic.get_analytic_group_contents(ems_id)# Query a specific analyticflight=123altitude_id="H4sIAAAAAAAEAG2Q0QuCMBDG34P+B/HdbZVUiApBPQT2kgi9rrn0YM7aZvbnN5JVUvdwfHD34/vu4iPXrbjTs+D7kksDF+DKezRC6ggSvzbmGmHc9z3qF6hVFZ4TMsOnQ5azmjc0AKkNlYz7A/Mm9GusUUkNZa00ijLj+BCTFd6UgApF/XQ68bx4SMHVvkyd1GjX6KytgFER46+FEZBfObOZ2db6eBBJEIlvVGfz4P+LhYRbZ29NyVCzgJD1MgitDIhrrj6+P/h04obj36VPLpuOeVIBAAA="# Pull out altitude with 100 samples through the file.query={"select":[{"analyticId":altitudeId}],"size":100}altitude=client.analytic.get_query_results(ems_id,flight,query)Database queryQuery and print the top 20 flight ids with a valid takeoff and landingquery={"select":[{"fieldId":"[-hub-][field][[[ems-core][entity-type][foqa-flights]][[ems-core][base-field][flight.uid]]]","aggregate":"none"},{"fieldId":"[-hub-][field][[[ems-core][entity-type][foqa-flights]][[ems-core][base-field][flight.exist-takeoff]]]","aggregate":"none"}],"filter":{"operator":"and","args":[{"type":"filter","value":{"operator":"isTrue","args":[{"type":"field","value":"[-hub-][field][[[ems-core][entity-type][foqa-flights]][[ems-core][base-field][flight.exist-takeoff]]]"}]}},{"type":"filter","value":{"operator":"isTrue","args":[{"type":"field","value":"[-hub-][field][[[ems-core][entity-type][foqa-flights]][[ems-core][base-field][flight.exist-landing]]]"}]}}]},"groupBy":[],"orderBy":[],"distinct":True,"top":20,"format":"display"}result=client.database.get_query_results(ems_id,'[ems-core][entity-type][foqa-flights]',query)pd=pandas.DataFrame(result.rows,columns=['Flight Record','Takeoff Exists'])print(pd)Async Database queryRun the same query as above, but with paging for a large number of result rowsquery['top']=5000000db_id='[ems-core][entity-type][foqa-flights]'response=client.database.start_async_query(ems_id,db_id,query)ifclient.is_error(response):error=client.get_error_message(response)raiseValueError(error)async_query_id=response.idtry:start_index=0batch_size=20000whileTrue:end_index=start_index+(batch_size-1)read_response=client.database.read_async_query(emsId,db_id,async_query_id,start_index,end_index)ifclient.is_error(read_response):break# Some kind of error occurrediflen(read_response.rows)>0:forrowinread_response.rows:print(row)ifnotread_response.has_more_rows:breakstart_index=end_index+1finally:client.database.stop_async_query(emsId,db_id,async_query_id)