News for hackers. Stuff that matters.
Re:Types for Python HTTP APIs by acemarke on Friday September 13, 2019 @06:17PM (#20967217)
I ran across FastAPI earlier this year and did a tiny prototype to play with it. Selling points for me:

- Integrates nicely with some existing libraries (Starlette, Pydantic)

- Well documented

- Auto-validation of endpoints from data models

- Auto-generation of OpenAPI schemas from those models

- Auto-serves live API docs from that schema

- Easy definition of sync and async endpoints

Again, it was just a tiny proof-of-concept prototype, but I'm sold on using it on future projects.

Re:Types for Python HTTP APIs by hyzyla on Saturday September 14, 2019 @05:56AM (#20969847)
But I found one drawback of using FastAPI - defining all inputs in handler function signature is looks bit complicated and verbose. I prefer one input with type that are structure of another types. Something like this:

  class CreatePostInput(InputClass):
       text: str
       user_id: str
       ...
  
  @handler.post('/post')
  def create_post(input: CreatePostInput):
      ...
Re:Types for Python HTTP APIs by ivalm on Saturday September 14, 2019 @02:54AM (#20969336)
> - Auto-generation of OpenAPI schemas from those models

Is there a package that can do a reverse? Can I give it an OpenAPI spec and get a code stump going?

Re:Types for Python HTTP APIs by BerislavLopac on Saturday September 14, 2019 @11:47AM (#20971543)
OpenAPI-generator [0], written in Java, can produce Python stumps, but I never liked that approach.

Connexion [1] is built on top on Flask and does routing and validation based on an OpenAPI spec.

I've recently started developing Pyotr [2], which does the same only based on ASGI and Starlette. It also includes a client module.

[0] https://openapi-generator.tech/

[1] https://connexion.readthedocs.io/

[2] https://github.com/berislavlopac/pyotr

Re:Types for Python HTTP APIs by drchaim on Saturday September 14, 2019 @09:50AM (#20970728)
https://github.com/zalando/connexion/

Solves most of the problems for that.