question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A REST API would be useful to access ATM from any other language and device through the web, and also to illustrate how the code is structured and might be extended.

From the project’s readme I get that the internal API’s are going to change and that it consequently might be a bit early to develop a REST API, but I wanted to see what was possible to do with the current code. The API currently serves:

  • Various GET endpoints for reading data from the four entities that are currently present in the database
  • 1 GET endpoint to run the worker.py script inside the virtualenv as a subprocess and retrieve it’s stdout and stderr
  • 1 POST endpoint to send a .csv file with the HTTP request, save the file to the atm/data directory and run enter_data on it.

No modifications were made outside of the rest_api_server.py file except to the requirements.txt file, adding flask and simplejson to the project dependencies.

TODO’s / caveats:

  • No AWS integration
  • api.py currently does not check if the uploaded filename is already present, so a CSV upload can rewrite a previously sent file with the same name. This needs fixing, but I thought that I should ask first if the atm/data directory is the right one to put new files in, and if storing UUID’s is ok with the project’s design before using them and doing a pull request.

Example api.py usage:

After following the readme’s installation instructions and running python scripts/rest_api_server.py on a separate shell under the virtualenv:

curl localhost:5000/enter_data -F file=@/path/file.csv

It should return:

{"success": true}

To see the created dataset:

curl localhost:5000/datasets/1 | jq

{
  "class_column": "class",
  "description": null,
  "size_kb": 6,
  "test_path": null,
  "k_classes": 3,
  "majority": 0.333333333,
  "d_features": 6,
  "train_path": "FULLPATH/file.csv",
  "id": 1,
  "n_examples": 150,
  "name": "file"
}

To see the created datarun:

curl localhost:5000/dataruns/1 | jq

{
  "status": "pending",
  "start_time": null,
  "description": "uniform__uniform",
  "r_minimum": 2,
  "metric": "f1",
  "budget": 100,
  "selector": "uniform",
  "priority": 1,
  "score_target": "cv_judgment_metric",
  "deadline": null,
  "budget_type": "classifier",
  "id": 1,
  "tuner": "uniform",
  "dataset_id": 1,
  "gridding": 0,
  "k_window": 3,
  "end_time": null
}

To run the worker.py script once:

curl localhost:5000/simple_worker | jq

after a while

{
  "stderr": "",
  "stdout": "huge stdout string with worker.py's output"
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:19 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
RogerTangoscommented, Sep 25, 2018

Hey there - I’m picking up this issue. I think @jobliz’s design was pretty good, and I’m going to propose a few more endpoints and decouple the API from the database

0reactions
csalacommented, Apr 25, 2019

The first read-only version of the REST API is already in master, so I’m closing this issue now so future enhancements can be added as new issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a REST API? - Red Hat
A REST API (also known as RESTful API) is an application programming interface (API or web API) that conforms to the constraints of...
Read more >
What is REST - REST API Tutorial
A REST API consists of an assembly of interlinked resources. This set of resources is known as the REST API's resource model.
Read more >
What is RESTful API? - RESTful API Beginner's Guide - AWS
RESTful API is an interface that two computer systems use to exchange information securely over the internet. Most business applications have to communicate ......
Read more >
What is a REST API? | IBM
A REST API is an API that conforms to the design principles of the REST, or representational state transfer architectural style. For this...
Read more >
Representational state transfer - Wikipedia
REST has been employed throughout the software industry and is widely accepted as a set of guidelines for creating stateless, reliable web APIs....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found