OpenAPITools / OpenAPITools/openapi-generator

[Python] How to make http asyncrhonous calls with generated python client

Open
#3,696 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python General: Question
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

I'm creating a auto-generated API client using the openapi-generator for python. This API has some asynchronous functions that returns lines of data: JSON asynchronously.

I would like to have a callback that get this data and process it on a separate thread but I don't know how to use the async=True option when the call is instantiated. As I show it return a Thread but I don't know how to set the callback for it.

openapi-generator version
➜ openapi-generator version
4.0.3
OpenAPI declaration file content or url

https://gitlab.com/snippets/1882068/raw

Note: this YAML is auto generated from a Doxygen documentation for RetroShare project using this

Command line used for generation
openapi-generator generate -i wrapper_openapi.yml -g python -o ../openapi-python-retroshare-api-wrapper
Steps to reproduce

You can generate the wrapper using the command above with the provided YAML or cloning this.

I tested this code:

thread = api_instance.rs_gxs_channels_turtle_search_request(async_req=True,              req_rs_gxs_channels_turtle_search_request=req_rs_gxs_channels_turtle_search_request)
result = thread.get()
print("should be printed")

The program just stop, the "should be printed" string is never printed until the connection is closed by the server, so is not async, so is not a separated thread or I don't know how to use it.

In addition I would like that the responses received asynchronously be processed in a callback function

Related issues/PRs

I just opened an stackoverflow question:

https://stackoverflow.com/questions/57486784/python-openapi-generator-how-to-make-http-asyncrhonous-calls

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated Python client call using async_req=True and thread.get(), then compare it with the openapi-generator command and the provided wrapper_openapi.yml. Determine whether the reported blocking behavior is expected and whether callback handling is supported; done means documenting or addressing the behavior with a reproducible result.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.