This invention provides a real-time Python API recommendation method based on context analysis. It features the following steps: first, extract call points within the Python code context; then, perform
type inference on each call point. If the
inference is successful, the inferred type callable method is used as the API candidate set; otherwise, a set of API candidates is generated from standard
library APIs, third-party
library APIs, and APIs defined in the current context; then, extract data flow sequences containing only true positives based on five constraints: assignment operations, loop structures, attribute access / calls, container access, and function parameter passing; then, through context analysis, collect three features: data flow sequence, token similarity, and co-occurrence rules, and
encode these features into feature vectors; then,
label the feature vectors and
train all labeled vectors using a
random forest model; finally, based on the trained
recommendation model, the recommendation results are ranked by probability
score and presented to the developer.