Live data from Hacker News

Types for Python HTTP APIs

instagram-engineering.com

1–10 of 55 posts

Re: Types for Python HTTP APIs

#4
The whole Type thing in Python and all the workarounds to make Python type-safish looks and feels absolutely pathetic. I have no idea why a company like Facebook takes so much time to apologize for the inadequacy of Python as a programming language in the broader sense. Especially since they are utilizing a service based architecture they easily could make the switch to a language that actually supports types. Also the obvious performance gains...

Re: Types for Python HTTP APIs

#5

The whole Type thing in Python and all the workarounds to make Python type-safish looks and feels absolutely pathetic. I have no idea why a company like Facebook takes so much time to apologize for the inadequacy of Python as a programming language in the broader sense. Especially since they are utilizing a service based architecture they easily could make the switch to a language that actually supports types. Also t…

[deleted]

Re: Types for Python HTTP APIs

#6

The whole Type thing in Python and all the workarounds to make Python type-safish looks and feels absolutely pathetic. I have no idea why a company like Facebook takes so much time to apologize for the inadequacy of Python as a programming language in the broader sense. Especially since they are utilizing a service based architecture they easily could make the switch to a language that actually supports types. Also t…

Why this sounds pathetic (?) for a company like Facebook which essentially made their original backend PHP (!) type safe and compiled by developing their own sub language Hack and compilers HHVM around it. Python always supported dynamic types but on run time ;) and nowadays also static.

Re: Types for Python HTTP APIs

#7

The whole Type thing in Python and all the workarounds to make Python type-safish looks and feels absolutely pathetic. I have no idea why a company like Facebook takes so much time to apologize for the inadequacy of Python as a programming language in the broader sense. Especially since they are utilizing a service based architecture they easily could make the switch to a language that actually supports types. Also t…

Especially since they are utilizing a service based architecture

They articles says it is mostly a monolith with several millions line of code.

Re: Types for Python HTTP APIs

#8
Nice writeup - I've been doing this type of thing for 10 years before type annotations by passing the types to the decorator and then using kwargs to supply defaults.

  @annotate(foo=int, bar=str)
  def view_func(foo=0, bar='hi there'):
    ...
The types could also be arbitrary callables to parse things like datetime and what not. I'd parse the params from either the get params or post data (json, urlencoded, etc).

But now I'm using graphene and graphql to handle all this -- it's a better way to do all of it imho. Of course this all came along after instagram, so you didn't have that choice back then.

Re: Types for Python HTTP APIs

#9
I’ve been working on a similar solution for Flask in K Health. Currently we have great serialisation / deserialisation from types to JSON, next step will be creating OpenAPI documents

Re: Types for Python HTTP APIs

#10
post #9

I’ve been working on a similar solution for Flask in K Health. Currently we have great serialisation / deserialisation from types to JSON, next step will be creating OpenAPI documents

You should check out Flask-Rebar, I am using it a lot in my projects and it's very nice. Does all of this automagically.
Post reply on HN