http2py should be able to make a python binder for any valid OpenAPI spec
#11
Replies: 2 comments
-
|
TW: ChatGPT: To generate a Python client library for an OpenAPI specification, you can use the Here are the steps to generate a Python client library from an OpenAPI specification using Install the pip install openapi-python-clientCreate a Python script that generates the client library: from openapi_python_client import generate
generate(
url='https://example.com/openapi.yaml',
project_name='example_api_client',
package_name='example_api_client'
)In this script, we use the generate function from the openapi_python_client library to generate the Python client library. The url argument is the URL or local path to the OpenAPI specification file. The project_name argument is the name of the Python package to create, and the package_name argument is the name of the top-level module in the package. Run the Python script to generate the client library: python generate_client.pyThis will generate a Python client library based on the OpenAPI specification file at the given URL or local path. Install the generated client library: cd example_api_client
pip install .
This installs the generated client library in your Python environment.Use the client library in your Python code: from example_api_client import ExampleApiClient
client = ExampleApiClient()
response = client.get_some_data()
print(response)In this example, we import the ExampleApiClient class from the generated client library, create an instance of the client, and call a method on the client to get some data. The response is then printed to the console. I hope this helps you generate a Python client library from your OpenAPI specification. Let me know if you have any further questions or concerns. |
Beta Was this translation helpful? Give feedback.
-
|
| Approach | Pros | Cons | Example Use Case |
|---|---|---|---|
| Dynamic/In-Memory | No files, fast, flexible | Less type safety, less doc | Prototyping, notebooks |
| Codegen/Temp | Full type safety, docs | Slower, temp files, import | Testing, short scripts |
| Codegen/Custom | Full control, reusable | More setup, cleanup needed | Production, CI/CD |
Would you like:
- A more robust version of the dynamic client (with query/body param handling, etc.)?
- A ready-to-use hybrid function?
- Or help integrating this into your workflow?
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
http2pyshould be able to make a python binder for any valid OpenAPI spec.There are OpenAPI-supported tools to do this out there, but I've heard from some colleague(s) that it creates a hard-to-use python object. If so, I still think it may be worth using it. [Addendum: I checked and indeed, it generates code for a whole package. Nice, but different than what we're going for in
http2py(no code generation there)]Q: How do we gauge (conditional pros/cons?) whether we'd rather an
http2py-made python binder, or a swagger-generated package, or a pypi published package that uses the same web-service under the hood?References
Here is a list of python integration tools.
Here is the only OpenAPI specs search engine I found.
In it you can find several tools that "render/use" the specs in some way. One I'd like to mention is the
GUItool. You give it the url of the specs and it makes this kind of playgrounds. See, notably, how they allow you to chain operations into pipelines.openapi-python-generator
SDK Generation from an OpenAPI Specification File
OpenAPI with Python — a state of the art and our latest contribution
Beta Was this translation helpful? Give feedback.
All reactions