Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HOWTO: Write Python API wrapper? [closed]

Tags:

I'd like to write a python library to wrap a REST-style API offered by a particular Web service. Does anyone know of any good learning resources for such work, preferably aimed at intermediate Python programmers?

I'd like a good article on the subject, but I'd settle for nice, clear code examples.

CLARIFICATION: What I'm looking to do is write a Python client to interact with a Web service -- something to construct HTTP requests and parse XML/JSON responses, all wrapped up in Python objects.

like image 484
hanksims Avatar asked Feb 05 '09 18:02

hanksims


People also ask

What is a Python wrapper for API?

An API wrapper provides a way to access an API through a particular programming language or interface, which can help streamline the process of making API calls.

What is a wrapper for an API?

API wrappers are language-specific kits or packages that wrap sets of XML API calls into easy-to-use functions. The wrapper programmatically calls multiple API calls without requiring user interaction, further automating projects. Veracode provides API wrappers for these languages: C# Java.

What makes a good API wrapper?

Idiomatic consistency Put simply, this means your wrapper should smell like language in which it is written — Ruby like Ruby, Java like Java, PHP like PHP, and so on. This usually comes into play when language conventions bleed through an API in the form of method and variable names.


1 Answers

I can't point you to any article on how to do it, but I think there are a few libraries that can be good models on how to design your own.

PyAws for example. I didn't see the source code so I can't tell you how good it is as code example, but the features and the usage examples in their website should be a useful design model

Universal Feed Parser is not a wrapper for a webservice (it's an RSS parser library), but it's a great example of a design that prioritizes usage flexibility and hiding implementation details. I think you can get very good usage ideas for your wrapper there.

like image 113
Ricardo Reyes Avatar answered Sep 18 '22 17:09

Ricardo Reyes