clams.restify package
Package providing wrapper class for running a CLAMS app as a HTTP app.
- class clams.restify.ClamsHTTPApi(cla_instance: ClamsApp)[source]
Bases:
Resource
ClamsHTTPApi provides mapping from HTTP verbs to Python API defined in
ClamsApp
.Constructor takes an instance of
ClamsApp
.- get() Response [source]
Maps HTTP GET verb to
appmetadata()
.- Returns:
Returns app metadata in a HTTP response.
- static json_to_response(json_str: str, status=200) Response [source]
Helper method to convert JSON output from a ClamsApp to a HTTP response.
- Parameters:
json_str – a serialized JSON .
status – a numerical HTTP code to respond.
- Returns:
A HTTP response ready to send.
- methods: t.ClassVar[t.Collection[str] | None] = {'GET', 'POST', 'PUT'}[source]
The methods this view is registered for. Uses the same default (
["GET", "HEAD", "OPTIONS"]
) asroute
andadd_url_rule
by default.
- post() Response [source]
Maps HTTP POST verb to
annotate()
. Note that for now HTTP PUT verbs is also mapped toannotate()
.- Returns:
Returns MMIF output from a ClamsApp in a HTTP response.
- put() Response [source]
Maps HTTP POST verb to
annotate()
. Note that for now HTTP PUT verbs is also mapped toannotate()
.- Returns:
Returns MMIF output from a ClamsApp in a HTTP response.
- class clams.restify.Restifier(app_instance: ClamsApp, loopback: bool = False, port: int = 5000, debug: bool = True)[source]
Bases:
object
Restifier is a simple wrapper that takes a
ClamsApp
object and turn it into a flaks-based HTTP server. For mapping between Python API and HTTP API, it relies onClamsHTTPApi
class.Constructor takes a
ClamsApp
instance and some options for flask configuration.- Parameters:
app_instance – A
ClamsApp
to wrap.loopback – when True, the flask wrapper only listens to requests from localhost (used for debugging).
port – Port number for the flask app to listen (used for debugging).
debug – When True, the flask wrapper will run in debug mode.
- run(**options)[source]
Starts a development server. See
serve_development()
.- Parameters:
options – any additional options to pass to the web server.
- serve_development(**options)[source]
Runs the CLAMS app as a flask webapp, using flask built-in development server (https://werkzeug.palletsprojects.com/en/2.0.x/).
- Parameters:
options – any additional options to pass to the web server.
- serve_production(**options)[source]
Runs the CLAMS app as a flask webapp, using a production-ready web server (gunicorn, https://docs.gunicorn.org/en/stable/#).
- Parameters:
options – any additional options to pass to the web server.
- test_client()[source]
Returns flask test client.