HOWTO: Write Python API wrapper? [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
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.

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.

My favorite combination is httplib2 (or pycurl for performance) and simplejson. As REST is more "a way of design" then a real "protocol" there is not really a reusable thing (that I know of). On Ruby you have something like ActiveResource. And to be honest, even that would just expose some tables as a webservice, whereas the power of xml/json is that they are more like "views" that can contain multiple objects optimized for your application. I hope this makes sense :-)

This tutorial page could be a good starting place (but it doesn't contain everything you need).

You should take a look at PyFacebook. This is a python wrapper for the Facebook API, and it's one of the most nicely done API's I have ever used.

You could checkout pythenic jobs, a nice, simple, but well-formed "Python wrapper around the Authentic Jobs ... API" as a good example. That's what I'm doing now :)

Related

Is it good to read Python Documentation to learn Python for a beginner? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I've started learning Python recently and started reading Head First Python and Learn Python The Hard Way. Both books doesn't seem to explain everything in detail. I wanna know if it's a good idea to read Python Documentation instead of these books. Any help would be appreciated. Thanks in advance!
The documentation has two parts; one is a basic tutorial which won't cover much beyond what you can find in the books, and the majority of it is a reference to the language itself. It is not a good learning resource, but it is (as good documentation is), an excellent reference for when you want to find out what a particular module does.
The documentation won't answer questions like "How do I download a file from the Internet?" (actually, it answers this specific question but the idea is that its not a teaching resource) but it will tell you what are all the methods of the urllib module, however you would already need to know that you need urllib to get the job done; this is the main problem when you are starting out.
I would say from the documentation you should probably skip the tutorial (especially if you are already reading a book), and then have a look at the standard library index which will give you an overview of what modules are available, broken down by function.
I would recommend the Programming Python book by Mark Lutz as a great starting point. It is quite a tome (at 1632 pages) but covers everything you need to know to be proficient in Python.
Once you have gone through that, the next book I would recommend is The Python Standard Library by Example by Doug Hellman. It is an excellent resource on how to use the comprehensive standard library.
Finally, after the two books you are now ready to solve real world problems and nothing helps more than having a cookbook/reference of sorts, for this I can recommend the following:
Python in Practice
Python Cookbook
Writing Idiomatic Python
If you want a comprehensive review of the language, the docs are your best resource.
http://docs.python.org/index.html
Nevertheless, you may prefer to start out with the tutorial (http://docs.python.org/tutorial/) and some introductory material such as the ones you've referenced, so that you can have some experience putting together the basics so that you have experiences to draw from when reviewing the docs, since the library reference (http://docs.python.org/library/index.html) and the language reference (http://docs.python.org/reference/index.html) don't necessarily have a lot of good examples, and frequently presume at least elementary knowledge of the language in its expositions.
The How-To's are a good in-depth review, with examples: http://docs.python.org/howto/index.html
The books are good to introduce you the language, with examples. You should definitely read them if you have time.
The documentation is useful to get technical details on some method, for a specific version of the language (eg Python 2.7.6 reference)
Finally, when you're developing an application, you can also learn by reading the source code, exploring where the code is going and what is happening. An excellent debugging tool is iPdb, which allows you to put breakpoints in your code and examine the current state at that position.
If the documentation is too crude, and the book too long, you can also try some online tutorial. Google is full of resources, like LearnPython.
It is, definitely :-).
I'd also read http://www.diveintopython3.net (or http://www.diveintopython.net for 2.x).

Building a website that interacts with DB and/or XML [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm looking to get into web development. My goal is to create some interactive webpages that interact with MS SQL databases (read/insert/updates), and also possibly sites that interact with XML files.
I've got some basic understanding of Python and Perl scripting. Can someone point me in the right direction in either of those languages to accomplish what i'm looking to do, or if it's easier to accomplish in another language what would that be?
Apologies if my stated goal is too broad.
I'd strongly suggest you to look into some of the web development frameworks. They take care of many low-level tasks which is needed in order to build a solid web page. I'm not very familiar with perl, so I can only suggest Python frameworks, especially one of the my favourites - Django. It has very good documentation which is essential for the first-timer. I believe you should be fine as long as you follow the official documentation.
Good luck
You can use SQL Alchamy in python, and lxml or the default ElementTree xml module for simple cases.
I have done both for a webservice I maintain, and they work nice.
You can also use a web development framework. I personally suggest Flask based on that it is a lightweight framework as opposted to django for instance. However, depending on your exact use case the latter might be better.

Good high-level python ftp/http lib? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I'm looking for a good, high-level python ftp client/server library. I'm working on a project that has "evolved" a small http/ftp library on top of ftplib/urllib/urllib2 from what was originally one function, and almost none of it was designed to be built upon. So now it's time to refactor kind of seriously, and I'd like to just switch to a library. The thing I'd most like to not deal with is robust-retry logic (like, keep retrying 15 times, or keep retrying until 12pm).
The problem that we've got right now is that we have about 10 separate grab() and put() functions. Aesthetically speaking, I'd rather have one of each with optional arguments along the lines of try_until=datetime(2009, 10, 7, 19) or retrys=15. We work with both binary and text data, so the functions would have to be reasonably smart about that. And we do way more grabbing than putting, so I can deal without the puts.
urlgrabber looks like exactly what I want, but there doesn't seem to have been any development for the last couple years and I'm not sure how compatible it is with 2.6. Anybody got much experience with this? Or opinions?
URLgrabber appears to be very mature, and since it's used by yum (and thus many Unix systems), I would expect it to be very stable. Python 2.x is largely backward compatible. You might encounter some warnings, but I would expect it to work suitably under Python 2.6.
Depending on the sort of application you are writing, you might want to consider twisted python, as it has http server and client code built in. However, it is a rather large departure from standard procedural python programming.
The big advantage of twisted for you is that it can handle your client requests in the background, handles retries and is very scalable.
Update
For a quick script that interacts with servers, see this serverfault answer:
https://serverfault.com/questions/66336/script-automation-login-enter-password-run-commands-save-output-locally
It recomends the tool expect
Expect is a tool for automating
interactive applications such as
telnet, ftp, passwd, fsck, rlogin,
tip, etc. Expect really makes this
stuff trivial. Expect is also useful
for testing these same applications.
And by adding Tk, you can also wrap
interactive applications in X11 GUIs.
Expect can make easy all sorts of
tasks that are prohibitively difficult
with anything else. You will find that
Expect is an absolutely invaluable
tool - using it, you will be able to
automate tasks that you've never even
thought of before - and you'll be able
to do this automation quickly and
easily.
Sounds good to me!

How to write a Web Service for Google App Engine? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I am really new to Python and I have been looking for an example on how to write a Web Service (XML - SOAP) in Python with Google App Engine with no luck.
Can anyone point me to an article or give me an example on how to do this?
I was curious about this myself and not finding anything I decided to try to get something to work. The short answer is that it turns out a SOAP service can actually be done using the latest alpha ZSI library. However it isn't simple and I didn't do much more than a simple request so it could fall apart with a complex type. I'll try to find time to write a tutorial on how to do it and edit this answer with more detail.
Unless this is a hard requirement I would do what jamtoday says and go with a REST or RPC service. The SOAP way could be filled with trouble.
Update: For anyone interested I've written a tutorial on how to deploy a SOAP service to the Google App Engine. It is long process so I'm just linking to it instead of pasting it all here.
If you want to do something with App Engine specifically, there are libraries that will make it much faster on your end. I'd recommend looking at the XML-RPC and REST examples.
http://appengine-cookbook.appspot.com/recipe/xml-rpc-server-using-google-app-engine/
http://github.com/fczuardi/gae-rest/tree/master
I know this is an old thread but just in case if someone happens to read this.
I have just start an open source project for creating web services on GAE.
Project site: http://code.google.com/p/webserviceservlet/
Hope this is helpful.
EDIT:
Just noticed that this is a python question and the link project is java project....
Here is a Python Web Services project that might be helpful.
EDIT
And here is a SOAP consuming demonstration....
You could take a look at the Bottle framework. It's a Python framework which with you can easily create a REST api.
In my opinion, REST is definitely better than SOAP. It can be easily consumed by any software able to speak http, and it's faster to implement.

Where can I learn more about PyPy's translation function? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I've been having a hard time trying to understand PyPy's translation. It looks like something absolutely revolutionary from simply reading the description, however I'm hard-pressed to find good documentation on actually translating a real world piece of code to something such as LLVM. Does such a thing exist? The official PyPy documentation on it just skims over the functionality, rather than providing anything I can try out myself.
This document seems to go into quite a bit of detail (and I think a complete description is out of scope for a stackoverflow answer):
http://codespeak.net/pypy/dist/pypy/doc/translation.html
The general idea of translating from one language to another isn't particularly revolutionary, but it has only recently been gaining popularity / applicability in "real-world" applications. GWT does this with Java (generating Javascript) and there is a library for translating Haskell into various other languages as well (called YHC)
If you want some hand-on examples, PyPy's Getting Started document has a section titled "Trying out the translator".
PyPy translator is in general, not intended for more public use. We use it for translating
our own python interpreter (including JIT and GCs, both written in RPython, this restricted
subset of Python). The idea is that with good JIT and GC, you'll be able to speedups even
without knowing or using PyPy's translation toolchain (and more importantly, without
restricting yourself to RPython).
Cheers,
fijal
Are you looking for Python specific translation, or just the general "how do you compile some code to bytecode"? If the latter is your case, check the LLVM tutorial. I especially find chapter two, which teaches you to write a compiler for your own language, interesting.
It looks like something absolutely revolutionary from simply reading the description,
As far as I know, PyPy is novel in the sense that it is the first system expressly designed for implementing languages. Other tools exist to help with much of the very front end, such as parser generators, or for the very back end, such as code generation, but not much existed for connecting the two.

Categories

Resources