A Flask app that runs a microservice on the local machine providing access to python utilities via API endpoints.
- python 3.8 or higher (can be installed using
venv
)
see https://realpython.com/python-virtual-environments-a-primer/
To run this in a virtual environment (from venv
folder):
- from project root:
pip install virtualenv
virtualenv venv
source venv/bin/activate
python -m pip install <package>
- e.g.
python -m pip install green
- To run the service,
flask run
on the command line. - To run with debugger and reloader active (recommended while developing),
export FLASK_ENV=development
beforehand
Running the app using flask will make it available on localhost.
flask run
should output the protocol, URL, and port on which the microservice is available. By
default, this is http://127.0.0.1:5000/
See /app.py
for details on routes, variables, and returns
In general, requests are made like this (NOTE: no trailing slash before the variables):
http://<host>:<port>/<module>/<function>?<arg_1_name>=<arg_1_value>&<arg_2_name>=<arg_2_value>&...
e.g.
http://127.0.0.1:5000/primes/nth_prime/?n=12
or, where an argument type is array/list (see /app.py for each route's syntax):
http://127.0.0.1:5000/combinations/combinations?source_list=1|2|3
In general, returns are a dict
with the format:
{
data_type: <function_return_data_type_name>,
result: <function_return>,
}
e.g.
{
data_type: "int",
result: 37,
}
from app root:
python -m unittest discover -s modules -p "*_test.py" --verbose
from app root:
green
green modules.combinations_test
green modules.permutations_test
etc.
green modules.combinations_test.CombinationsTest
green modules.combinations_test.NChooseRTest
etc.
- There are no plans at this time to actively maintain this repo. It's a public fork of a personal project that I use to speed up development when I need to reuse utilities and algorithms between languages locally. That said, if someone else gets some use out of this repo or finds it interesting, great!