<div dir="ltr">here's a json doc example with an object_hook from <a href="https://docs.python.org/3/library/json.html">https://docs.python.org/3/library/json.html</a><div><br></div><div><div>Specializing JSON object decoding:</div><div><br></div><div>>>></div><div>>>> import json</div><div>>>> def as_complex(dct):</div><div>... if '__complex__' in dct:</div><div>... return complex(dct['real'], dct['imag'])</div><div>... return dct</div><div>...</div><div>>>> json.loads('{"__complex__": true, "real": 1, "imag": 2}',</div><div>... object_hook=as_complex)</div><div>(1+2j)</div><div>>>> import decimal</div><div>>>> json.loads('1.1', parse_float=decimal.Decimal)</div><div>Decimal('1.1')</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 2, 2017 at 9:23 AM, Aaron Elmquist <span dir="ltr"><<a href="mailto:elmq0022@umn.edu" target="_blank">elmq0022@umn.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">actually you probably need to specify all the keyword arg in the __init__ .</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 2, 2017 at 9:22 AM, Aaron Elmquist <span dir="ltr"><<a href="mailto:elmq0022@umn.edu" target="_blank">elmq0022@umn.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I think it would be easy to load what I'm assuming is JSON into a python dictionary and use it from there.<div><br></div><div>If you need an object with additional methods you could instantiate it from the dictionary. Something like:</div><div><br></div><div>class MyClass(object):</div><div> def __init__(self, parameters):</div><div> self.a = a</div><div> ....</div><div><br></div><div>or you could get real fancy with setattr ... (maybe not a good idea though)</div><div><br></div><div>then you could load it with:</div><div><br></div><div>my_obj = MyClass(**dict_from_json_data)</div><div><br></div><div><br></div><div>Honestly, I think I would just work with the dictionary directly if I could. </div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-4495505563209003714h5">On Tue, May 2, 2017 at 9:01 AM, Lukasz Szybalski <span dir="ltr"><<a href="mailto:szybalski@gmail.com" target="_blank">szybalski@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-4495505563209003714h5"><div dir="ltr"><div><div><div><div><div><div><div><div><div><div>Hello,<br></div>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)<br><br><i>myobject = Rest</i>(<a href="https://dev.twitter.com/rest/public" target="_blank">https://dev.twitter.com/r<wbr>est/public</a>)<br><br></div>or<br><a href="http://developer.edmunds.com/api-documentation/vehicle/" target="_blank">http://developer.edmunds.com/a<wbr>pi-documentation/vehicle/</a><br></div>or <br>....<br><br><br></div>then myobject.get.searchTweet('chic<wbr>ago python')..?<br></div>or what ever the syntax is.<br></div>This would issue a rest api call and return object back.<br><br></div>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:<br><strong><br></strong>"GET /1.1/search/tweets.json?q=chic<wbr>ago%20python":<br><br></div><div>+Access anything that was build with:<br></div><a href="http://swagger.io/" target="_blank">http://swagger.io/</a><br></div><div>openapi<br><br></div><div><br>Thanks<br></div>Lucas<br><br><br>--<br></div>LucasManual.com<br><br></div>
<br></div></div>______________________________<wbr>_________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org" target="_blank">Chicago@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/chicago" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/chicago</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>