[Chicago] REST API to Python Class?

Chris Foresman foresmac at gmail.com
Tue May 2 10:55:08 EDT 2017


You guys are talking about building a Python object that basically has attributes that would match the dictionary from doing a `json.loads(response.content)`. That’s not what Lucas is asking for; what he wants is something that will simply abstract using the actual API by getting metadata from the main endpoint. That only works with APIs built with something like OpenAPI/Swagger, etc. Django REST Framework does this is the latest versions, for instance, and CoreAPI has a client that will do this with any API that conforms to OpenAPI, Swagger, CoreAPI, etc.


Chris Foresman
foresmac at gmail.com




> On May 2, 2017, at 9:51 AM, Anish Krishnan <anish.krishnan.1216 at gmail.com> wrote:
> 
> You could create a factory function called rest() that returns a new instance as Aaron has described. You could unpack the values in the function rather than in the object constructor.
> 
> On May 2, 2017 9:33 AM, "Aaron Elmquist" <elmq0022 at umn.edu <mailto:elmq0022 at umn.edu>> wrote:
> actually you probably need to specify all the keyword arg in the __init__ .
> 
> On Tue, May 2, 2017 at 9:22 AM, Aaron Elmquist <elmq0022 at umn.edu <mailto:elmq0022 at umn.edu>> wrote:
> I think it would be easy to load what I'm assuming is JSON into a python dictionary and use it from there.
> 
> If you need an object with additional methods you could instantiate it from the dictionary.  Something like:
> 
> class MyClass(object):
>     def __init__(self, parameters):
>         self.a = a
>         ....
> 
> or you could get real fancy with setattr ... (maybe not a good idea though)
> 
> then you could load it with:
> 
> my_obj = MyClass(**dict_from_json_data)
> 
> 
> Honestly, I think I would just work with the dictionary directly if I could.  
> 
> 
> On Tue, May 2, 2017 at 9:01 AM, Lukasz Szybalski <szybalski at gmail.com <mailto:szybalski at gmail.com>> wrote:
> Hello,
> Does anybody know if there is a tool that would auto-read rest API and create a python like object that you can interact in python? (like: pysimplesoap and its WSDL() but for REST)
> 
> myobject = Rest(https://dev.twitter.com/rest/public <https://dev.twitter.com/rest/public>)
> 
> or
> http://developer.edmunds.com/api-documentation/vehicle/ <http://developer.edmunds.com/api-documentation/vehicle/>
> or 
> ....
> 
> 
> then myobject.get.searchTweet('chicago python')..?
> or what ever the syntax is.
> This would issue a rest api call and return object back.
> 
> I think a lot of projects are building python api that are more and more json exposed. I'm looking for a tool that would allow me to access these using python, instead of rest:
> 
> "GET /1.1/search/tweets.json?q=chicago%20python":
> 
> +Access anything that was build with:
> http://swagger.io/ <http://swagger.io/>
> openapi
> 
> 
> Thanks
> Lucas
> 
> 
> --
> LucasManual.com
> 
> 
> _______________________________________________
> Chicago mailing list
> Chicago at python.org <mailto:Chicago at python.org>
> https://mail.python.org/mailman/listinfo/chicago <https://mail.python.org/mailman/listinfo/chicago>
> 
> 
> 
> 
> _______________________________________________
> Chicago mailing list
> Chicago at python.org <mailto:Chicago at python.org>
> https://mail.python.org/mailman/listinfo/chicago <https://mail.python.org/mailman/listinfo/chicago>
> 
> 
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20170502/a45d927f/attachment.html>


More information about the Chicago mailing list