New to working with APIs, any good tutorials/books/guides?
On 22Feb2014 02:45, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
> On Fri, 21 Feb 2014 12:12:00 -0800, ApathyBear wrote:
> > [...] or in any other language
> > for that matter? If an API is defining rules in C, is all hope lost for
> > trying to use it in python?
> If an API is defined for a C library or function, then, no, you can't use
> it in Python, or Lisp, or Ruby, just as you can't use a Lisp function in
> C or Forth or Pascal. Not unless one or the other language makes special
> provision to allow such cross-language communication.
What Steven says is true, at the simplest level.
However, MANY popular APIs that come with (for example) C libraries
and which are documented in terms of a C programming interface have
Python modules whose entire purpose in life is to present a Python
API which in turn accesses the C API for you.
For one example, consider the "bsddb" Python 2 module, which is
part of the standard library: if you have Python 2, you have the
The BSD dbm libraries are C libraries with a C API. However, the
bsddb module is a Python module which contains python calls which
operate on BSD dbm files. If you're using Python, you can use this
module, which of course has a _Python_ API, to use the BSD dbm
So: if you have some library which has a C API, it is possible that
there is a Python module which interfaces to it, and that module
will have a Python API. You may need to fetch such a module from a
third place, such as PyPI.
Cameron Simpson <cs at zip.com.au>
Who are all you people and why are you in my computer? - Kibo