https://github.com/acao/python-api
A koa REST api for python script stdin/stdout
https://github.com/acao/python-api
Last synced: 3 months ago
JSON representation
A koa REST api for python script stdin/stdout
- Host: GitHub
- URL: https://github.com/acao/python-api
- Owner: acao
- Created: 2016-08-14T19:26:12.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-14T19:26:39.000Z (almost 9 years ago)
- Last Synced: 2025-01-16T21:36:06.715Z (4 months ago)
- Language: Python
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
## Intro
Allows one to create an HTTP server around multiple python scripts. Great for doing computations and such with numpy/scipy, etc
Credit to @astenta and @egassama for providing the python scripts as part of this challenge
## Getting Started
1. ``npm install``
2. ``npm start``## Requirements
* Python 2.7
* Node 6.22
* watchman (for development - brew install watchman)## Add scripts
1. Add the script to python/ directory
2. Add it to scripts in config.toml:```js
[[scripts]]
singleArg = true # default false
name = "rainfall"
path = "Uniaxial_CycleCount/CalculateUniaxial.py"
```## Python script behavior
* should accept stdin arguments from sys.argv as strings or JSON strings
* should print the results as a JSON string to stdout - print() seems to work fineEventually, this could also be installed globally and executed with local commands
## Making HTTP requests
* can accept a single argument if the singleArg is set to true (helpful for sending an array as a single arg to the python script)
### POST /calculate/rainfall
**1. HTTP Request**
```json
[
[0,1,2,3,4,6],
[0,200,-100,300,-200,100],
[0,0.02,-0.01,0.03,-0.02,0.01]
]
```**2. Executes (behind the scenes)**
```
$: python python/Uniaxial_CycleCount/CalculateUniaxial.py "[[0,1,2,3,4,6], [0,200,-100,300,-200,100], [0,0.02,-0.01,0.03,-0.02,0.01]]"
```
**3. Which Returns: (behind the scenes)**
```
[["6 to 1", 0.01, 200, 150], ["4 to 2", 0.01, 200, 0]]
```
**4. HTTP Response**```json
[
[
"6 to 1",
0.01,
200,
150
],
[
"4 to 2",
0.01,
200,
0
]
]
```### POST /calculate/hyopthetical
**Request**
```json
[
[0,1,2,3,4,6],
[0,200,-100,300,-200,100],
[0,0.02,-0.01,0.03,-0.02,0.01]
]
```**Response**
```json
[
[
"6 to 1",
0.01,
200,
150
],
[
"4 to 2",
0.01,
200,
0
]
]
```