Skip to content

Using Type4Py Rest API

Amir M. Mir edited this page Feb 19, 2022 · 4 revisions

Usage Example

Type4Py's Rest API provides a predict endpoint, which accepts a Python source file via a POST request. A minimal example is given below in Python.

import requests

# Replace `example.py` with your desired Python source file.
with open('example.py') as f:
    r = requests.post("https://type4py.com/api/predict?tc=0", f.read())
    print(r.json())

The response contains type information in JSON format. See here for the description of the response format. For other programming languages, it should be possible to write a similar code like the above example.

Note 1: The sent Python file should have valid syntax.

Note 2: Above example uses type4py.com, our public API. Use localhost:5001 instead of type4py.com if Type4Py's Docker image is running.

JSON Response

Clone this wiki locally