Python in a Nutshell book cover by Martelli, Ravenscroft, Holden, and McGuire β€” O'Reilly Python 3 language reference

Pages

771

Published

2023

Python ✨ New

Python in a Nutshell

A Concise Desktop Reference for Python 3 β€” Language, Libraries, and Best Practices

Get a definitive answer to any Python question fast, from core syntax and data structures to the standard library and modern best practices.

Python in a Nutshell is the working reference you keep open while you code. Covering Python 3 in depth, it gives you authoritative, precise answers on language semantics, built-in types, the standard library, and the idioms that experienced Python developers rely on daily. Whether you are debugging a subtle scoping issue, reaching for the right data structure, or navigating the standard library without guessing, this book delivers the answer without making you wade through a tutorial.

About this book

Some books teach you Python. This one is the one you reach for after you already know Python and need to get something right. Python in a Nutshell, written by four experienced Python practitioners and published by O'Reilly, is a dense, accurate, desktop reference covering the full Python 3 language and a broad cross-section of its standard library.

The book is organized the way a working programmer thinks. You can start at the language reference chapters to resolve a question about variable scope, object model behavior, or descriptor protocol, then move to the library chapters to find the right module and understand its interface without hunting through online docs. Every section is written to be read on its own, so you can jump in wherever your current problem takes you.

Coverage spans the core language thoroughly: types and objects, expressions and statements, functions and closures, classes and metaclasses, exceptions, iterators, generators, and the async model introduced in modern Python 3. The library chapters cover I/O, text handling, data formats, networking, concurrency, and more β€” chosen for practical relevance rather than encyclopedic completeness.

  • Complete coverage of Python 3 type system, including type hints and the typing module
  • Detailed treatment of Python's data model, descriptors, and metaclasses
  • Standard library modules for file I/O, networking, concurrency, and data handling
  • Async programming with asyncio, including coroutines and task management
  • Packaging and distribution essentials for sharing your own code
  • Extension and embedding guidance for integrating Python with C

At 771 pages, this is not a lightweight pamphlet. It earns the shelf space by being the most reliable single source you can consult when the answer actually matters. If you write Python regularly, this book pays for itself the first week you use it.

🎯 What you'll learn

  • Navigate Python's object model confidently, including descriptors, slots, and metaclasses
  • Apply type hints and the typing module correctly to real codebases
  • Use iterators, generators, and coroutines in production-quality code
  • Select the right standard-library module for I/O, text processing, networking, and concurrency tasks
  • Reason precisely about Python's scoping rules and closure behavior
  • Structure async code with asyncio, coroutines, and tasks without common pitfalls
  • Package and distribute Python projects using current tools and conventions
  • Extend or embed Python in C for performance-critical integration work

πŸ‘€ Who is this book for?

  • Intermediate to advanced Python developers who want a fast, authoritative reference rather than another tutorial
  • Engineers moving from Python 2 to Python 3 who need a precise map of what changed and why
  • Backend developers building APIs or data pipelines who need reliable standard-library coverage at their fingertips
  • Data engineers and scientists who write production Python and need to move past guessing at language behavior
  • Technical leads or senior engineers who review Python code and need a credible source to settle disputes

Table of contents

  1. 01

    Getting Started with Python

    Sets up the environment and introduces the Python interpreter, covering installation, the interactive shell, and how Python finds and executes code.

  2. 02

    The Python Language

    Covers core language syntax: literals, variables, expressions, statements, control flow, and the rules that govern how Python evaluates and executes code.

  3. 03

    The Python Type System

    Examines Python's built-in types in depth β€” numbers, strings, bytes, lists, tuples, sets, and dictionaries β€” with precise behavioral details for each.

  4. 04

    Functions and Functional Programming

    Explains function definition, argument passing, closures, decorators, and the functional programming tools available in the standard library.

  5. 05

    Object-Oriented Python

    Covers classes, inheritance, the descriptor protocol, metaclasses, and the full Python data model so you can predict and control how objects behave.

  6. 06

    Exceptions and Context Managers

    Describes Python's exception hierarchy, how to raise and handle exceptions correctly, and how to write context managers with both classes and generators.

  7. 07

    Iterators, Generators, and Async

    Explains the iterator protocol, generator functions and expressions, and Python's async model including coroutines, tasks, and the asyncio event loop.

  8. 08

    The Standard Library

    Surveys the most useful standard-library modules across I/O, text, data formats, networking, and concurrency with enough detail to use them without guessing.

  9. 09

    Extending and Embedding Python

    Shows how to write C extension modules and embed the Python interpreter in a larger application, with practical guidance on the CPython C API.

  10. 10

    Packaging and Distribution

    Walks through the tools and conventions for packaging Python projects, declaring dependencies, and publishing to PyPI for others to install.

Frequently asked questions

What version of Python does this book cover?

The fourth edition covers Python 3, reflecting modern language features including type hints, asyncio, and current standard-library interfaces. Python 2 is not the focus.

Do I need to be a Python beginner to benefit from this book?

No. This is a reference and mid-to-advanced practitioner guide, not a tutorial. Readers who already write Python day-to-day will get the most out of it.

Does the book include runnable code examples?

Yes, the text includes code examples throughout to illustrate language behavior and library usage. Check O'Reilly's companion page for any downloadable materials.

Is this book suitable as a first Python book?

It is not designed for beginners. If you are learning Python for the first time, a tutorial-style book will serve you better before you reach for this reference.

How is this different from reading the official Python documentation?

The book provides curated, cross-referenced, editorially reviewed coverage written by experienced practitioners, with context and judgment that raw reference docs do not offer.

Does the book cover third-party libraries like NumPy or Django?

The focus is the Python language itself and the standard library. Third-party frameworks and scientific libraries are outside its scope.

You might also like

πŸ“¬ Weekly Newsletter

Stay ahead of the curve

Get the best programming tutorials, data analytics tips, and tool reviews delivered to your inbox every week.

No spam. Unsubscribe anytime.