Difference between API and API library/Wrapper - python

I'm kinda confused. So I understand that If we want to grab data from an API, we can just call that API url in whatever language we are using ( example in python, we can do urllib.open( url of api) and then load the json). My question is, if we can just open the url in any language, what's the point of the API libraries that developers usually have on the site ( library wrapper for python, java, c#, ruby, etc). Do we need to use a specific library to call an API in that specific language? Can we not just open up the API url in any language? What's the point of having a library in each language if we can just extract the API in each of those languages?

You don't need a library for the client. However, developers tend to like libraries because it helps with things like creating authorization headers, creating parameterized URLs and converting response bodies into native types.
However, there are good/bad ways of building these kinds of libraries. Many libraries hide the HTTP API and introduce a whole new set of issues that HTTP interfaces were originally designed to avoid.

Related

API endpoint confusion

Disclaimer: I am new to working with APIs
I am working on leveraging gimbals API and am trying to figure out what exactly end points are? I realize that they link to a server, but how exactly are they used in development?
Are the endpoints used to link to specific sources of data?
I am using python(django) and it would be great to understand exactly how access and or change information on gimbals end.
PS- When looking at the gimbal api, I noticed that they have a REST api and some other mobile stuff going on. If I am building a web platform, I would only be interested in the REST API portion correct?
An endpoint in a RESTful API is generally just a URL. The URL represents some kind of resource. If it was an order processing API, the resources would be things like customers, orders, etc.
You interact with these resources by making HTTP requests of various sorts; GET if you want to know the content of a resource, POST if you want to change something, and so on. Have a look at this for basic information on REST and web APIs.
You don't need Django to interact with a RESTful API that someone else provides. All you really need is python's urllib, and maybe the json module, if they're sending the data in JSON. The REST API they provide is probably the main thing they want developers using, but if they have multiple APIs then it's hard to say which one is right for you without understanding the application better.

OData Python Library available?

I was wondering if any OData Python libraries are available to produce and consume OData?
There are implementations for different languages:
http://www.odata.org/libraries/
But I couldn't find Python so far. I don't mean IronPython by the way. The library should be just usable in Python.
i am the author of the library at http://code.google.com/p/odata-py/
it's still in its early stages but it provides the most basic functionalities (create, read, update). Don't hesitate to drop a message if you see a bug or want to contribute ;)
I've recently added some OData modules to a Python package I maintain for an e-Learning project called Pyslet. The project is hosted on Github here: https://github.com/swl10/pyslet
I wrote an introductory blog post demonstrating the OData consumer features here: http://swl10.blogspot.co.uk/2014/02/a-dictionary-like-python-interface-for.html
I started my own OData 4.0 consumer project some time ago. It's based on the requests library and is pure Python. It's rather minimal as I've only implemented things I needed for work. Check it out on my github.
Works kinda like this:
from odata import ODataService
url = 'http://services.odata.org/V4/Northwind/Northwind.svc/'
Service = ODataService(url, reflect_entities=True)
Product = Service.entities['Product']
query = Service.query(Product)
query = query.filter(Product.ProductName.startswith('Queso'))
query = query.order_by(Product.UnitPrice.desc())
for product in query:
print(product.ProductName)
Here is a version that is targeting Google App Engine: http://code.google.com/p/odata-py/
I've been experimenting with the spec and wrote a simple server for Python called MyOhData: https://bitbucket.org/dowski/myohdata/src
please check this link
http://www.odata.org/libraries/
ODataPy (Python)
ODataPy is an open-source Python library that implements the Open Data Protocol (OData). It supports the OData protocol version 4.0. It is built on top of ODataCpp using language binding. It is under development and currently serves only parts of client and client side proxy generation (code gen) aspects of OData.
V4 Client GitHub
ODataStore for CoreData (iOS)
The ODataStore for CoreData is an iOS static library and a Mac OS X Framework to use V3 OData services with the CoreData Framework from Apple. V4 OData services will be supported in the future. The development language is Objective-C.
V3 Both Link
Pyslet Python Package (Python)
Pyslet is a Python package for Standards in Learning Education and Training. It implements a number of standards including OData v2 with both client and server capabilities.
V2 Both Link
OData4ObjC
This library makes it easy for iOS app developers to interact with data in any OData-compliant web service. It supports metadata-aware client-side code generation and full CRUD with query. If someone exposes a data model via OData, OData4ObjC makes it easy to get that model onto your iOS device.
V1-3 Client GitHub
I've looked as well after getting an intro to OData and it looks like there isn't one as of yet unfortunately. I'll be keeping an eye out for one as I'm sure one will surface.
Update 2016
OData Libraries lists two python libraries that support OData. With pyslet looking to be the most active since it has had commits in the last few months and several releases. I haven't tried either of them so I can't really say if they work well or not.

How to use python for a webservice

I am really new to python, just played around with the scrapy framework that is used to crawl websites and extract data.
My question is, how to I pass parameters to a python script that is hosted somewhere online.
E.g. I make following request mysite.net/rest/index.py
Now I want to pass some parameters similar to php like *.php?id=...
Yes that would work. Although you would need to write handlers for extracting the url parameters in index.py. Try import cgi module for this in python.
Please note that there are several robust python based web frameworks available (aka Django, Pylons etc.) which automatically parses your url & forms a dictionary of all it's parameters, plus they do much more like session management, user authentication etc. I would highly recommend you use them for faster code turn-around and less maintenance hassles.

Noob Question: Python + Twitter + App Engine - Oauth

I'm sorry but I'm having some trouble implementing Oauth within my app engine python project.
I've been working from http://github.com/tav/tweetapp, but I don't think I have a strong enough grasp on this platform to understand how to implement this class within my main.py I'm building the rest of my app in.
This maybe a feeble attempt, but here is what I have so far:
twa = twitter_auth
client = twa.OAuthClient('twitter')
I've created a source folder within my project called "twitter_auth" and that contains a file within it called "twitter_auth.py" which contains the above linked library, and a file called __ init__.py (no space) which is completely empty.
I really have no idea what to do from here :/
Let me recommend taking a look at the tweepy library and some example tweepy apps. Specifically here: http://github.com/wasauce/tweepy-examples
This shows how to use oauth to authenticate a user: http://github.com/wasauce/tweepy-examples/tree/master/appengine/oauth_example/
As Hagge said, it sounds like your issue is more with the tweetapp library than with App Engine. However, if you would like to know more about OAuth on App Engine and if I may be allowed to link to myself, my two articles on the topic seem to be reasonably popular.
The tweetapp library was a an early prototype for Twitter OAuth on twitter. Tav did the heavy lifting and I deployed the site http://twitteroauth.appspot.com , using some of the tweetapp library. The actual source of that site is here (I need to update the site to point here): http://github.com/ryanwi/twitteroauth
I am still using it in production, but, it has aged and does not work for all API calls. I'd recommend trying a different, more up to date and maintained library as others have mentioned.
But, take a look at the twitteroauth source if you want to try to get a first attempt working.
These two are on Twitter's list
http://github.com/brosner/python-oauth2
http://code.google.com/p/oauth-python-twitter2/
I'm not familiar with that library, but after a quick look and seeing the warning that it is not maintained I'd search for something better. I implemented a simple Twitter connection based on Tornado's auth: see an example of how to make Twitter API calls here (and an authentication example here). In case you don't want to use tipfy, I recommend implementing the python-twitter library in your framework of choice.

Python Web Services

Elementree has become the accepted standard for interacting with xml. What is the prevalent web service/SOAP library in use today?
I'm not sure about an accepted standard, but I've found SOAPpy to be fairly straight-forward and useful library for handling SOAP-based web services.
SOAPy is a SOAP/XML Schema Library for Python. Given either a WSDL or SDL document, SOAPy discovers the published API for a web service and exposes it to Python applications as transparently as possible.
IBM provide a good walk-through and example on their site for getting started with SOAPpy.
SOAPpy's no longer under active development, but is instead being folded into Zolera SOAP Infrastructure (ZSI) at the Python Web Services Project. This project however has alos not seen much activity since November last year.
Old question, but for anyone else who is asking this question I've had good success with suds:
https://fedorahosted.org/suds/
soaplib is very easy to use and seems to be active.
http://web.archive.org/web/20090729125144/https://wiki.github.com/jkp/soaplib/

Categories