This might seem like an extremely simple and stupid question yet i can't find a convenient answer.
I'm trying to use google's reverse geocodding api with django, as the website explains (at https://developers.google.com/maps/documentation/geocoding/start?csw=1#ReverseGeocoding) I'm supposed to send a request to the url :
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=<_api_key>
But I can't find an appropriate way to send this request using django to google api.
To me it seems something so simple will be doable by some method built-in django but all I could find was modules to install.
If there's no way but installing other python modules which one's the best?
Well, the most straightforward way would be to install requests library and simply call:
result = requests.get(your_link)
You can find additional information (e.g., how to authenticate, use cookies, etc., as well as how to access data in response) in the library's docs. The requests library is very well written, very intuitive and simple to use. Quite a lot of smart people and companies use it, too, so it's not a half-baked library someone just hacked out over the weekend (as of this moment, it has 6060 commits and 595 contributors on GitHub).
If you absolutely must avoid external libraries, why not try urllib.request. It's a bit more complicated, and even the docs themselves recommend using requests if you prefer higher-level interface. But you definitely can get the job done with it. To get started, you can read the docs on how to use it to fetch data. Read this thread for an example of how to extract json from a response you'd get with urllib.
Related
I've searched internet but couldn't find a good solution. I'm looking for something that pretty specific - a golang copy of aiohttp_swagger.
That is a Python package which does magical things. In the endpoint handler method, one write some comment code and it'll be automatically parsed and generates swagger documentation. When the server is up and running, a special URL /api/doc handler will be inserted into the server where people can see it live.
I understand it's tied into the implementation of aiohttp framework and the way Go is used, web framework is not as popular (not using one myself), but I still like that solution very much and would like to find something in the Go land.
So my question is a bit open I guess: is there an equivalent (or rough) of aiohttp_swagger package in Go?
go-swagger does it based on doc comments: https://goswagger.io/generate/spec.html
go-restful has a builder for creating swagger 2.0 documents: https://github.com/emicklei/go-restful-openapi
I used to get twitter data using R with an xml package. Seems like they no longer use xmls and only use json. I tried a few methodologies with json and I keep getting an error saying API 1.0 not available anymore and I need to use API 1.1. Fine but there seems to be no clear documentation in how to.
Can someone guide me to a location or provide sample code for getting twitter data.
I used to do this in R but seems like python is better for this. If someone can provide a guide in either or both would be very much appreciated.(or some sample code with explanation)
Thanks
I recommend using sixohsix's twitter library for Python.
There is some documentation on the github page, and if you're familiar with at least a bit of Python (I didn't know Python very well when I started using it), then it's pretty easy to use. It supports API v1.1 (v1.0 is deprecated and doesn't even work anymore, afaik).
With some Python scripts on a Ubuntu netbook I was able to continuously query the API for almost a year now, without one crash. I wouldn't recommend R for this, especially if you're after a lot of data.
You can still use R for data analysis, you can actually plug it into your Python scripts directly using rpy2.
This package might be useful. It was just released a few days ago.
twitteR package for R
The Twitter API was updated from version 1.0 to version 1.1. Many codes are now defunct since authentication is needed. Many blog posts with code samples are no longer valid.
For Python, I prefer the bear's package.
For R, I think the standard package is twitteR.
Whatever you do, you'll have to authenticate your "application" as a developer: link.
I'm not trying to start a religious war, but I personally really don't like api version information in the URL of a resource. I think the best way to do it is via the Accept header of the resource or adding a ?version=2 to the query string. If you are curious about this topic. There are a number of good (an passionate) posts on StackOverflow on the topic. Here is a good thread here. Also, IMHO, a good blog post here by Steve Klabnik. Again, these are just my perferences, and I'm not trying to create a thread on this topic (again).
I'm currently looking for a Django package to help with creating a RESTful API. After some reading, it seems like TastyPie has most of what I want/need and is well supported (and has really good docs). And I'm just wondering if there is a way to implement a different versioning scheme? Has anyone else out there done this? Is there another package that might work more the way I want?
Yes, you can use Accept headers or any other method to version your API, and do this in a way that is not specific to whatever Django API package you are using. One easy way to do this is to add some middleware to check for the headers on relevant requests and then load the appropriate URL conf depending on the version specified.
There are several simple apps on github that use URL routing middleware that you can customize to meet your needs.
Also, Tastypie is amazing and I highly recommend it over Piston after using both.
I have a requirement to build a client for Shopify's API, building it in Python & Django.
I've never done it before and so I'm wondering if someone might advise on a good starting point for the kinds of patterns and techniques needed to get a job like this done.
Here's a link to the Shopify API reference
Thanks.
Your question is somewhat open-ended, but if you're new to Python or API programming, then you should get a feel for how to do network programming in Python, using either the urllib2 or httplib modules that come with more recent versions of Python. Learn how to initiate a request for a page and read the response into a file.
Here is an overview of the httplib module in Python documentation:
http://docs.python.org/library/httplib.html
After you've managed to make page requests using the GET HTTP verb, learn about how to make POST requests and how to add headers, like Content-Type, to your request. When communicating with most APIs, you need to be able to send these.
The next step would be to get familiar with the XML standard and how XML documents are constructed. Then, play around with different XML libraries in Python. There are several, but I've always used xml.dom.minidom module. In order to talk to an API, you'll probably need to know to create XML documents (to include in your requests) and how to parse content out of them. (to make use of the API's responses) The minidom module allows a developer to do both of these. For your reference:
http://docs.python.org/library/xml.dom.minidom.html
Your final solution will likely put both of these together, where you create an XML document, submit it as content to the appropriate Shopify REST API URL, and then have your application deal with the XML response the API sends back to you.
If you're sending any sensitive data, be sure to use HTTPS over port 443, and NOT HTTP over port 80.
I have been working on a project for the last few months using Python and Django integrating with Shopify, built on Google App Engine.
Shopify has a valuable wiki resource, http://wiki.shopify.com/Using_the_shopify_python_api. This is what I used to get a good handle of the Shopify Python API that was mentioned, https://github.com/Shopify/shopify_python_api.
It will really depend on what you are building, but these are good resources to get you started. Also, understanding the Shopify API will help when using the Python API for Shopify.
Shopify has now released a Python API client: https://github.com/Shopify/shopify_python_api
I think you can find some inspiration by taking a look at this:
http://bitbucket.org/jespern/django-piston/wiki/Home
Although it is directly opposite what you want to do (Piston is for building APIs, and what you want is to use an API) it can give you some clues on common topics.
I could mention, of course, reading obvious sources like the Shopify developers forum:
http://forums.shopify.com/categories/9
But I guess you already had it in mind :)
Cheers,
H.
Has anybody created a nice wrapper around Yahoo's geo webservice "GeoPlanet" yet?
After a brief amount of Googling, I found nothing that looks like a wrapper for this API, but I'm not quite sure if a wrapper is what is necessary for GeoPlanet.
According to Yahoo's documentation for GeoPlanet, requests are made in the form of an HTTP GET messages which can very easily be made using Python's httplib module, and responses can take one of several forms including XML and JSON. Python can very easily parse these formats. In fact, Yahoo! itself even offers libraries for parsing both XML and JSON with Python.
I know it sounds like a lot of libraries, but all the hard work has already been done for the programmer. It would just take a little "gluing together" and you would have yourself a nice interface to Yahoo! GeoPlanet using the power of Python.