Fluent Python: Implementing intuitive and productive APIs
Python is so consistent that we can often infer the behavior of new objects by assuming they work like the built-ins. The Python data model is the foundation of this consistent behavior. Luciano Ramalho explores the construction of Pythonic objects: classes that feel "natural" to a Python programmer and leverage some of the best language features by implementing key protocols of the data model.
Talk Title | Fluent Python: Implementing intuitive and productive APIs |
Speakers | Luciano Ramalho (ThoughtWorks) |
Conference | O’Reilly Open Source Convention |
Conf Tag | |
Location | Austin, Texas |
Date | May 16-19, 2016 |
URL | Talk Page |
Slides | Talk Slides |
Video | |
An API is considered Pythonic when it supports convenient and suitable Python idioms. For example, Python programmers expect that any collection is iterable and supports the len() function. Empty collections should evaluate “falsy” in boolean contexts. Objects of any type should have a user-friendly string representation as well as another display format that doesn’t hide details and is useful for debugging. Objects of several types support operators such as + and * when it makes sense. Pythonic objects are one of the keys to high programmer productivity with the language. All of these object features, and more, are defined in the Python data model: the API that applies to Python objects in general, from plain integers to collections and even to functions and classes—when we treat them as first-class objects in the language. The data model makes Python so consistent that we can often infer the behavior of new objects by assuming they work like the built-ins. Luciano Ramalho outlines the most important of the special methods defined in the data model and demonstrates how to implement objects that behave as “naturally” as the built-in types and therefore deserve to be called Pythonic. The entire presentation and exercises will be guided by doctests, which support a form of behavior-driven design (BDD) and allow attendees to check their progress in the hands-on parts of the tutorial.