[ Web Proxy ]
URL:
Viewing: https://wiki.python.org/moin/../python/platforms/../../python/security/../archive/API.html [Back]  [Original]

API - Python Wiki
Python Wiki
psf/wiki 0 0
Copy page

API

Legacy Wiki Page

This page was migrated from the old MoinMoin-based wiki. Information may be outdated or no longer applicable. For current documentation, see python.org.

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(), youd 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 its 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.

Back to top

Web Proxy Viewer  |  New URL  |  Original Page