Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66810 > unrolled thread
| Started by | ApathyBear <nirchernia@gmail.com> |
|---|---|
| First post | 2014-02-20 23:59 -0800 |
| Last post | 2014-02-22 14:30 +1100 |
| Articles | 8 — 6 participants |
Back to article view | Back to comp.lang.python
New to working with APIs, any good tutorials/books/guides? ApathyBear <nirchernia@gmail.com> - 2014-02-20 23:59 -0800
Re: New to working with APIs, any good tutorials/books/guides? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-21 09:19 +0000
Re:New to working with APIs, any good tutorials/books/guides? Dave Angel <davea@davea.name> - 2014-02-21 06:49 -0500
Re: New to working with APIs, any good tutorials/books/guides? ApathyBear <nirchernia@gmail.com> - 2014-02-21 12:12 -0800
Re: New to working with APIs, any good tutorials/books/guides? Joel Goldstick <joel.goldstick@gmail.com> - 2014-02-21 15:21 -0500
Re: New to working with APIs, any good tutorials/books/guides? Roy Smith <roy@panix.com> - 2014-02-21 20:52 -0500
Re: New to working with APIs, any good tutorials/books/guides? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-22 02:45 +0000
Re: New to working with APIs, any good tutorials/books/guides? Cameron Simpson <cs@zip.com.au> - 2014-02-22 14:30 +1100
| From | ApathyBear <nirchernia@gmail.com> |
|---|---|
| Date | 2014-02-20 23:59 -0800 |
| Subject | New to working with APIs, any good tutorials/books/guides? |
| Message-ID | <9f4db1e7-800f-4fd2-945d-d0972a440071@googlegroups.com> |
I don't understand how APIs work to save my life. I am a complete beginner. In fact, I am a bit confused on what API even means and what the meaning entails. I am fairly competent with python, though I do lack some real world experience. Regardless, any tutorials/books/guides that deal with API for a complete beginner would be awesome. Thanks. PS: Something that can explain SDKs would be helpful as well.
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-02-21 09:19 +0000 |
| Message-ID | <53071a38$0$29985$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #66810 |
On Thu, 20 Feb 2014 23:59:16 -0800, ApathyBear wrote: > I don't understand how APIs work to save my life. I am a complete > beginner. In fact, I am a bit confused on what API even means and what > the meaning entails. API stands for "Application Programming Interface", and it essentially means the set of interfaces, calling conventions, functions, methods etc. of a language, library or even a single function. For example, in Python, the API of the len() function is really simple: - len() takes a single mandatory argument; - that argument must be a sequence, mapping, or some other object with a __len__ method; - otherwise len() will raise TypeError; - len() will always return an int; - which is supposed to be the length of the sequence or mapping. That's pretty much the API for the function len(). Simple, isn't it? Now, obviously the API for an entire library is more complicated. It includes rules for how many and what kind of arguments each function, class or method expects; what values they are allowed to be; what sort of values will be returned; what exceptions will be raised, and so forth. Basically, when you read the manual for a language or library, that's documenting the API. That's all there is to it. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2014-02-21 06:49 -0500 |
| Message-ID | <mailman.7225.1392983179.18130.python-list@python.org> |
| In reply to | #66810 |
ApathyBear <nirchernia@gmail.com> Wrote in message: > I don't understand how APIs work to save my life. I am a complete beginner. In fact, I am a bit confused on what API even means and what the meaning entails. > > I am fairly competent with python, though I do lack some real world experience. Regardless, any tutorials/books/guides that deal with API for a complete beginner would be awesome. > At its most fundamental, the API is the documentation that makes it practical to reuse code you didn't write yourself, or that you wrote longer than 30 days ago. "Application Programmer Interface" describes the functions, the classes, the globals. The semantics, the algorithms, the assumptions, the gotchas. The license, the restrictions. If you inherit a body of code and it doesn't define an API, chances are it's throwaway code, good only for examples. > > > PS: Something that can explain SDKs would be helpful as well. > SDK is "Software Development Kit" Generally it's a bunch of related APIs plus one or more of tools like editor, compiler, interpreter, debugger, profiler, test generator, IDE, source control system, bug tracker, etc. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | ApathyBear <nirchernia@gmail.com> |
|---|---|
| Date | 2014-02-21 12:12 -0800 |
| Message-ID | <3fa5e368-a47c-4a7e-80dc-c5333fb5603e@googlegroups.com> |
| In reply to | #66810 |
Thanks, I think I have an understanding of what they are, but now am still a little confused on how one goes about using it: how am I supposed to know how to use an API in python? 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? Examples??
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2014-02-21 15:21 -0500 |
| Message-ID | <mailman.7236.1393014096.18130.python-list@python.org> |
| In reply to | #66845 |
[Multipart message — attachments visible in raw view] — view raw
On Feb 21, 2014 3:15 PM, "ApathyBear" <nirchernia@gmail.com> wrote: > > Thanks, I think I have an understanding of what they are, but now am still a little confused on how one goes about using it: how am I supposed to know how to use an API in python? 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? > > Examples?? Google to find some sport that interest you. Read the docs and tutorial > -- > https://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2014-02-21 20:52 -0500 |
| Message-ID | <roy-457C2C.20520621022014@news.panix.com> |
| In reply to | #66845 |
In article <3fa5e368-a47c-4a7e-80dc-c5333fb5603e@googlegroups.com>, ApathyBear <nirchernia@gmail.com> wrote: > Thanks, I think I have an understanding of what they are, but now am still a > little confused on how one goes about using it: how am I supposed to know how > to use an API in python? 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? API is a very generic term for Application Programming Interface. It's just the protocol that you need to follow to communicate with some kind of system of software package. The documentation for an API should describe what operations are available, how you send data to it, and how it sends things back to you. Beyond that, there's not a whole lot that can be said because there are so many different kinds of APIs with vastly different interfaces.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-02-22 02:45 +0000 |
| Message-ID | <53080f5d$0$29985$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #66845 |
On Fri, 21 Feb 2014 12:12:00 -0800, ApathyBear wrote:
> Thanks, I think I have an understanding of what they are, but now am
> still a little confused on how one goes about using it: how am I
> supposed to know how to use an API in python?
*scratches head*
Er, first you learn how to program in Python, then you read the API
documentation and do what it says. If the documentation says that the
function requires a single string argument, then you give the function a
single string argument.
I suspect that either your question is much more subtle and complicated
than your actual words allow, or you're making things much, much, much
more complicated than they actually are. In an earlier post, you said you
had some experience programming in Python. If your code works, then you
know how to use the APIs of the functions and libraries that you used.
Here I am using the API for the len() function:
alist = [1, 2, 3]
number_of_items = len(alist)
That's all. Easy, wasn't it? I'm using the API for the len() function.
If you were asking for help with some *specific* API ("I don't understand
the multiprocessing module!"), that I could get. Some APIs are
complicated, or badly designed, or badly written, or require advanced
understanding. But APIs *in general* can be as simple as len().
> 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.
It might be better for you to give us concrete examples of what you don't
understand, rather than to continue talking in vague generalities.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Cameron Simpson <cs@zip.com.au> |
|---|---|
| Date | 2014-02-22 14:30 +1100 |
| Message-ID | <mailman.7250.1393041395.18130.python-list@python.org> |
| In reply to | #66863 |
On 22Feb2014 02:45, Steven D'Aprano <steve+comp.lang.python@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 bsddb module: http://docs.python.org/2/library/bsddb.html#module-bsddb 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 library. 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. Cheers, -- Cameron Simpson <cs@zip.com.au> Who are all you people and why are you in my computer? - Kibo
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web