Please note: This wiki is currently running in test mode after an attack on January 5 2013. All passwords were reset, so you will have to use the password recovery function to get a new password. To edit wiki pages, please log in first. See the wiki attack description page for more details. If you find problems, please report them to the pydotorg-www mailing list.

API is a shortcut for "Application Programming Interface".

Loosely defined, API describes everything an application programmer needs to know about piece of code to know how to use it. The idea is that the programmer knows all Signatures of classes and methods; their parameters, parameter types (or behaviour) as well as return values.

A programmer should always write against interface (API), not against implementation. This is especially important in Python. If you know a class has method subfrob(), you'd be better off with

if hasattr(obj, 'subfrob'):
    do_something(obj)
else:
    well_do_something_else

instead of using isinstance(obj, SomeSpecificClass). Effectively, this is applying idiom "if it walks like a duck, quacks like a duck..." it's a duck alright. Controlling behaviour depending on class instance used is more like programming to implementation, whereas programming against "signature" is more like programming against interface.

An example of API can be found at Voicent Simple Telephone Call API. The published class is used to encapsulate the implementation details.

API (last edited 2008-11-15 14:00:23 by localhost)