Leanpub Header

Skip to main content

Topics

Python

From a first program to the interpreter's internals, Django to pandas to PyTorch, the language as told through the free samples of the Leanpub books about Python.

Created from the free samples of 39 Leanpub books and the descriptions and tables of contents of 20 more, with every source cited.

Python is a high-level, general-purpose programming language, created by Guido van Rossum in the Netherlands in the late 1980s and first released in 1991. Its design puts readability first: blocks are marked by indentation, types are checked at run time, memory is garbage-collected, and the standard library is large enough that the language is described as "batteries included".[1] The qualities that made it a teaching language made it the working language of system administrators and web developers and, above all, of data analysis and machine learning, and it has ranked among the most used programming languages for well over a decade.

Python today means Python 3. The 2008 release broke compatibility with Python 2, the two coexisted for more than a decade, and Python 2 reached the end of its life in 2020; the books read for this article span that transition. The language now moves by annual releases, 3.13 being current when the newest of them were written, and the tooling around it has moved faster: pip, virtual environments, conda and lately uv for packages; Jupyter notebooks for exploratory work; pytest for tests; Django, Flask and FastAPI for the web; NumPy, pandas, scikit-learn and PyTorch for numbers. Most current work on language-model applications and AI agents is written in it too.

This article covers the language and its object model, the standard library and the tools around it, web and desktop applications, data analysis and scientific computing, machine learning and AI, and Python at work in operations, hardware and production pipelines. Its sources are the free samples of the Leanpub books listed at the end: where a sample states something, the sentence cites it; the rest is general knowledge of the language.

Where to start

The sources are unusually clear about who they are for. A reader who has programmed in another language can start with The Python Apprentice, which treats the object model and reference semantics early and leads into two further volumes,[2] or with 100 Page Python Intro, a deliberately short guide tested against Python 3.13 for readers who know the basics of programming and are willing to read a manual.[1] Python 101 starts from installation and goes past the basics into small applications and packaging, though its text is pinned to Python 3.8.[3] Build applications in Python the anti textbook is a short free introduction that ends in a working command-line program.[8] A reader who has never programmed at all is better served by Introduction to GIS Programming, which begins at Python novice before any geospatial work,[29] or, for the mathematically inclined, by Discrete Mathematics for Computer Science, whose Python projects run in the browser.[12]

Learners who have the syntax and stall at a particular step have a book for the step: Learn Python With No Programming Experience: Why, How, and When to Use Functions spends a chapter on why functions exist before any syntax,[19] Object Oriented Programming with Python does the same for classes,[21] and TLDR: Data Structures and Algorithms covers data structures with basic Python as its only prerequisite.[45] From there The Python Journeyman, Python 201 and Practice Python Projects are the intermediate reading,[22][25][11] and Inside The Python Virtual Machine and The Python Master the advanced.[24][23]

For the data work that brings most people to the language, A Hands-On Introduction to Essential Python Libraries and Frameworks (With Code Samples) is an orientation, a few pages on each of about forty libraries,[4] and Effective Pandas, by a pandas core developer, is the next step once some pandas is in hand, though its text dates from 2016.[43]

History

Van Rossum began Python as a hobby project at the Centrum Wiskunde & Informatica in Amsterdam, as a successor to the ABC language, and named it after Monty Python's Flying Circus. One survey of the ecosystem retells the start: a language meant to be easy to read and write, whose first version, 0.9.0 in 1991, already had modules, exceptions, and lists, dictionaries and tuples as its core types.[4] Python 2.0 followed in 2000. The non-profit Python Software Foundation holds the language's intellectual property, and for most of its life van Rossum guided it as "Benevolent Dictator for Life";[2] he stepped back in 2018 and a steering council has governed since.

Python 3.0 (2008) made print a function, changed string formatting and division, and removed features judged outdated; later releases added async/await and type annotations while keeping compatibility.[4] Code for one version will generally not run on the other, and one introduction written while both were common told its readers that Python 3 was the future and to use it if at all possible.[2] The library records the long overlap: an unofficial ebook of the official Python 2.7 tutorial from 2014,[5] a Django textbook for Python 2.7 or 3.5,[6] a PDF toolkit guide for Python 2.7 and 3.3+ that explains virtualenv before the venv module that replaced it,[7] a 2019 primer that still opens on Python 2 against 3,[8] and a GUI toolkit whose Python 3 port needed a code name, Phoenix.[9]

The newest samples show where the language stands. A hundred-page introduction is tested against Python 3.13.0,[1] a regular-expressions guide against 3.13.1,[10] a project book against 3.13.3;[11] the second edition of Python 101 was rewritten for 3.8, its author updating every chapter rather than patching the first.[3]

The language

Python is small enough to learn in a week and deep enough to fill a trilogy. Its surface is a handful of statement types, a few built-in collections and a function syntax; beneath it is an object model in which everything is an object with a type, and a scoping discipline most programmers meet only when it surprises them.

Design

Python is strongly typed, in that every object has a definite type, and dynamically typed, in that nothing is checked before the code runs; the best description of its type system is duck typing, where an object's suitability for a context is decided at run time. It is general-purpose, less suited only to extremely time-sensitive or memory-constrained work. Calling it "interpreted" is a slight misstatement: Python is compiled to bytecode first, but invisibly, so the experience is of running code the moment it is edited. Whitespace delimits blocks, which removes a great deal of punctuation and makes all Python code look alike in important ways.[2]

The reference implementation, CPython, is written in C; Jython targets the Java Virtual Machine, IronPython the .NET platform, and PyPy, written in a restricted Python called RPython, has a just-in-time compiler that makes it much faster for some programs.[2][3] Distributions wrap the interpreter with packages: Anaconda, aimed at data science and installed with its own conda tool, and WinPython, which runs from a USB stick on a locked-down Windows machine. Python also runs on Android and iOS through apps, and on a Raspberry Pi costing as little as ten dollars.[3]

Much of the appeal is the interactive shell, the REPL, where an expression's value is printed without print() and _ holds the last result.[11] IDLE, the editor that ships with Python, is built on the standard library's tkinter; Thonny, PyCharm, Spyder, Jupyter and VSCodium are the usual alternatives.[1] Authors outside the Python world choose it for the same reasons: a discrete mathematics text because the syntax is close to natural language, almost every snippet is under ten lines and the interactive mode invites experiment;[12] a genetic-algorithms book because an entry-level programmer can follow its low-ceremony code, which is why it avoids third-party modules.[13] The language's aesthetic is written down in the Zen of Python, whose "simple is better than complex" one cheat sheet prints at the foot of its first page.[14]

Core constructs

The built-in types are a beginner's first month. Integers are unbounded and floats double precision; // rounds towards the smaller integer; None, zero, empty strings and empty containers are false and everything else true, with not binding tighter than and, and and tighter than or.[15] Strings take single, double or triple quotes, and f-strings embed expressions.[14] Lists are ordered and mutable, indexed from zero with negative indices from the end; tuples are lists that cannot change; dictionaries hold key-value pairs iterated with items(), keys() or values(); sets hold unique elements and test membership in constant time.[14][15] A list's sort is Timsort, and append with pop makes a stack.[15] Slicing, [start:stop:step] on any sequence, has a puzzle book of its own,[16] fifty puzzles of the "what does this print" kind cover the rest of the syntax,[17] and comprehensions, a list or set built from a for clause in one expression, are the idiom beginners are told to reach for.[15]

Control flow is if/elif/else, for over any iterable, and while; input() returns a string, converted with int() or float().[14] A guide for PowerShell users sets each beside its equivalent, print() against Write-Host, input() against Read-Host, to learn the new language through the known one.[18] Functions are defined with def, take arguments with defaults, return a value and carry a docstring.[14] One short book exists only to say why they matter: they chunk code, let a bug be fixed in one place, give a task a name, and are the step out of scripting towards object-oriented programming.[19] Errors are exceptions handled with try, except and else; files open under with, which closes them on the way out.[14]

Objects, scopes and classes

Everything in Python is an object, and a variable is a name bound to one; names have no type of their own. Namespaces are dictionaries, and a name is looked up locally, then in enclosing functions, then in the module's globals, then the builtins. Assigning to a global inside a function creates a local instead, which is why global exists; nonlocal does the same for an enclosing function's variable and is what makes a closure such as a counter factory work.[20] eval and exec run a string as an expression or a suite of statements with optional dictionaries for globals and locals; replacing the builtins there is how an online interpreter sandboxes user code,[20] and passing user input to eval is unsafe outside a tool run only by its author.[11]

A class statement is executed, not declared: running it creates a class object, and the body's namespace is not a scope the methods can see, so a class attribute is reached through the class name. The class of a class is type, and a class can be rebuilt by running its body with exec into a dictionary and calling type with the name, the bases and that dictionary.[20] In everyday code a class has __init__, methods taking self and subclasses calling super(),[14] an introductory course teaches constructors and reference semantics through a Flight class,[2] and a short in-progress book covers inheritance and method resolution, polymorphism, operator overloading and exceptions for readers who find the object-oriented part hard.[21]

Below that, the simplicity ends. A training company's trilogy maps the depth: an apprentice volume on the core language, collections, exceptions, comprehensions, generators, classes, files and unit testing;[2] a journeyman volume on packages, closures and decorators, properties, iteration protocols, multiple inheritance, the collection protocols, context managers and introspection;[22] and a master volume on __getattribute__, slots, descriptors, instance creation, metaclasses, class decorators and abstract base classes.[23] A single intermediate text covers much the same ground, from the object model through generators, coroutines, decorators, metaclasses and the import system.[20]

Inside the interpreter

What CPython does with a file is a pipeline: source to parse tree, abstract syntax tree and symbol table, then to code objects holding bytecode; a frame object per call; and an evaluation loop in the C file ceval.c that executes opcodes, keeps the block stack for exceptions and implements generators. One book follows a piece of Python down that path and ends by extending the language.[24] The parser and the loop have both been reworked recently, so the CPython version an account describes matters. Two consequences reach every programmer: the global interpreter lock lets one thread run bytecode at a time, so CPU-bound parallelism uses processes, and one introduction treats threads, processes, profiling and debugging together as the intermediate layer;[3] and because the target is a virtual machine, PyPy can keep the language and change the machine.[3]

The standard library and tooling

"Batteries included" is a claim about the standard library, and the library is large. Around it has grown a second layer of tools for packaging, environments, testing and notebooks that a Python programmer now needs almost as much as the language.

The standard library

Command-line tools begin with sys.argv and the -c option that runs a one-line program,[11] and grow into argparse, which replaced optparse: a parser with a description and epilogue, required and optional arguments with defaults and types, short and long names and mutually exclusive groups, producing help text for free.[25] The collections module supplies ChainMap, which layers mappings so that command-line arguments override environment variables which override defaults, with defaultdict, deque, namedtuple and OrderedDict; the same tour covers contextlib, functools, itertools, typing, unittest and the concurrency modules.[25]

Text processing has the string methods and re. Regular expressions are a small language for sanitising, extracting and replacing text, and Python's dialect resembles Perl's with significant differences; re.search returns a match object or None, so it reads naturally in an if, patterns are raw strings, and re.I ignores case. One book works from there through anchors, groups, lookarounds, flags and Unicode to the third-party regex module, every feature from REPL examples the reader retypes;[10] another pairs each feature with a video and a puzzle.[26] subprocess runs shell commands, which is how a terminal agent gets its hands,[27] and datetime is the standard clock, though bindings can disagree with it: QuantLib's Date takes day, month, year.[28]

Environments, packaging and testing

Packages install with pip, spelled python -m pip install so they land in the interpreter you mean; --user installs for one account and -U upgrades.[7] Isolation is a virtual environment, the virtualenv package for Python 2 and early 3 and the venv module since 3.3, a folder holding a copy of the interpreter and pip that is activated before use.[7] One agent-building book makes "never install into the system Python" a rule, since AI libraries move fast and conflict with system packages.[27] pipenv folds pip and virtualenv into one tool,[9] and conda, with Miniconda as its small installer, manages environments that hold non-Python dependencies, which is why the geospatial and deep-learning books set it up first and then introduce uv as the fast alternative.[29][30] A production-practice guide uses uv for dependencies and for packaging a project for PyPI,[31] and pinning a version, pip install pycaret[full]==3.0.0, is how a book keeps its examples running.[32] Distribution to users is separate: a cross-platform package, a Windows executable and installer, and a Mac application are each a chapter,[3] and GUI books end with PyInstaller.[9]

Testing has two homes. The standard library's unittest closes the apprentice curriculum,[2] and pytest, which runs any function starting with test_ with no boilerplate, is what new code uses: a coding-agent book writes four tests before its main loop and, because model calls are slow, expensive and non-deterministic, adds a FakeBrain test double so the suite never makes one,[27] and a clean-architecture text assumes pytest and mocks as its prerequisite.[33] The notebook is Python's other interface: a Jupyter notebook mixes prose with code cells and their outputs, numbered In [N] and Out [N], in one shared scope, with data frames and plots rendered inline.[28] JupyterLab is the current interface and the classic Notebook its predecessor,[32] covered in a 2018 guide from sharing through Binder and Colab to nbconvert, widgets, debugging and kernels for other languages.[34] Their limits in production motivate a guide that pairs each practice with one tool: Git, uv, pytest, Hydra for configuration, Loguru for logging, Pandera for data validation, DVC for data versioning, GitHub Actions and marimo for reproducible notebooks.[31]

Web and desktop applications

Python reached the web early and the desktop earlier, and both traditions are well represented in the library's samples.

Django

Django, released in 2005, is the full-stack framework: an object-relational mapper, templates, forms, authentication, sessions and an admin site, organised in what its users call Model-View-Template. Two editions of a University of Glasgow textbook teach it by building one application, Rango, a directory of categories and pages, from the terminal, a virtual environment, pip and Git through models, templates, forms, static files, authentication, sessions, Bootstrap, jQuery and AJAX to deployment on PythonAnywhere.[6][35] The method is design first: before any code the reader draws a three-tier architecture, a browser, a Django application and the SQLite database Python ships with, then wireframes, URL mappings for the index, about and category pages, and an entity-relationship diagram whose fields are already Django types. The authors make the one-to-many assumption between categories and pages explicit and tell the reader to write such assumptions down. The book is, in its own words, not designed to be read but typed along with.[6] The Django 2 edition adds class-based views and unit testing,[35] and a Django sheet sits among the beginner cheat sheets.[14]

Flask, FastAPI and APIs

Flask (2010) is the microframework: routing, requests and templates, everything else the developer's choice. Its brevity shows in the samples. A security book's target is a Flask app whose file route takes a path parameter and opens it, so an encoded ../etc/shadow reads the password file; the same book stages a cross-site scripting attack and its cure, leaving the template engine's autoescaping on and never trusting user input.[36] A machine learning guide serves a Keras model from a Flask POST route and deploys it to App Engine with one command.[37] A clean-architecture text uses Flask as the web layer over a domain model kept free of frameworks, with SQLAlchemy and PostgreSQL or MongoDB behind repositories.[33] FastAPI, built on type hints and async, serves a BERT model in a PyTorch project book,[38] Streamlit turns a model into a web page with no web code,[32] and the ecosystem survey lists Flask, FastAPI, Django, Dash and Pyramid with pros and cons.[4] At the architectural end, a 2026 book presents event sourcing as a pattern language in fifteen chapters of working Python, from domain events and aggregates through event stores and snapshots to process managers, as a companion to the author's eventsourcing library.[39]

Desktop applications

Three toolkits cover the desktop. Tkinter is in the standard library, builds IDLE,[1] and suffices for a tic-tac-toe game with a computer opponent.[11] wxPython binds the C++ wxWidgets toolkit, first released in 1998, and draws native widgets on Windows, Mac and Linux; its hello world creates a wx.App, a wx.Frame for the window and a wx.Panel inside it, which is what makes tabbing between widgets work, then enters MainLoop(), and real code puts frame and panel into classes calling super().[9] PyQt5 wraps Qt: widgets and layouts, signals and slots, Qt Designer, database-backed views, plotting with PyQtGraph and matplotlib, threads and packaging.[40] Qt's other binding, PySide, is the interface toolkit of film and games pipelines.[41]

Documents and text

ReportLab has generated PDFs from Python since 2000, and Wikipedia's "Download as PDF" is built on it. Its pdfgen canvas is painted in points, 72 to the inch, from the bottom-left corner, so a US letter page is 612 by 792; a five-line program creates a Canvas and calls drawString, showPage and save. Above it sits PLATYPUS for paragraphs, tables and flowables, and beside it PyPDF2, pdfminer and PyFPDF.[7] An introductory text's tutorials run XML, JSON, CSV, SQLite, Excel and PDF.[3] Other writing systems need other tools: Japanese has no spaces between words, so tokenisation is itself the problem, and one book teaches fugashi, a Cython wrapper for the MeCab analyser with the unidic-lite dictionary, from a one-line install through a project that censors proper nouns and unknown words.[42] The survey's text shelf is spaCy, NLTK, TextBlob, CoreNLP and Gensim.[4]

Data analysis and scientific computing

NumPy gave Python a fast array, and pandas, built on it, gave it the DataFrame: a labelled table indexed by position, by label and by boolean mask, on rows, columns and hierarchical indexes alike. A pandas core developer writing in 2016 counted seven of the fifteen most-voted pandas questions on Stack Overflow as questions about indexing, and explained why: the old .ix accessor chose label- or position-based behaviour from the data's type, so one slice meant different things on different frames, and since pandas 0.12 .loc takes labels and .iloc positions. The same chapter explains the SettingWithCopy warning, which comes from chained indexing, two bracket operations in a row where pandas cannot promise the first returned a view rather than a copy; back-to-back square brackets mean trouble, and a single .loc[rows, cols] is the fix. MultiIndexes follow, higher-dimensional data in a two-dimensional table, worked on 471,949 US flight records.[43] Exploration has a common shape, shape, seaborn distribution plots, a log transform for a skewed target, a correlation matrix and a check for missing values,[37] and the survey's data shelf is pandas, NumPy, Seaborn, SciPy and Matplotlib.[4]

From notebook to production is an engineering problem. A guide for data scientists lists the symptoms, a notebook that becomes a mess, environments that break, results that cannot be reproduced, and answers each with a practice and a tool, beginning with version control, where tagging the commit behind a published result is what lets it be reproduced months later.[31] Databases have come to the notebook: DuckDB, an in-process analytical database, has a Python client beside its command line and a spatial extension, taught from the first SELECT.[44] The geospatial stack, GeoPandas, Rasterio, Leafmap and Geemap over Google Earth Engine, comes after a core-Python part and a conda environment.[29] Quantitative finance uses Python as the interactive front end to a C++ library: the QuantLib cookbook chose the Python bindings and Jupyter for interactivity and for matplotlib and pandas, opens on the Date, Period, Calendar and Schedule classes, advancing a date sixty business days on the US and Italian calendars, and closes with translating the examples to C++.[28]

Python is also the language mathematics and algorithms are taught in. A discrete mathematics text carries 225 snippets among 464 problems, tests divisibility with % and searches with range(10 ** 4), noting that range is a generator in Python 3;[12] a free data-structures guide explains hash tables through a motel manager and then shows that set() and dictionaries are hash sets and hash maps, with constant-time lookup and the hashable requirement on keys.[45] A concepts-first data engineering introduction says it is not about code in any one language, and still has a section on Python with SQL.[46]

Machine learning and AI

Python is the language of machine learning; one guide for AI beginners calls it the most widely used language for AI development.[47] The reason is the libraries, which the ecosystem survey lists by shelf: scikit-learn, PyTorch, TensorFlow, XGBoost, LightGBM, Keras and PyCaret for modelling; MLflow, Kubeflow and ZenML for operations; SHAP, LIME and InterpretML for explanation; OpenCV, scikit-image and Pillow for images.[4]

An end-to-end project shows how they fit. A guide loads 48,895 New York Airbnb listings into a DataFrame, log-transforms the skewed price, scales numeric columns with MinMaxScaler and one-hot encodes the categorical ones, since encoding Brooklyn as 1 and Manhattan as 2 would make Manhattan twice Brooklyn, joins the two in a make_column_transformer, splits with train_test_split, trains a Keras Sequential network with dropout and early stopping, Keras being TensorFlow's official high-level API, and serves the saved model through Flask.[37] A from-scratch book implements the algorithms instead: K-means as Point and Cluster classes pulling a colour palette from interface screenshots, and multinomial naive Bayes with Laplace smoothing on film reviews cleaned with BeautifulSoup and NLTK stop words.[48] A pipeline-first introduction organises the material by stage, cleaning with pandas, resampling, feature selection, PCA, then scikit-learn models;[49] PyCaret's low-code workflow of set up, compare, create, tune, predict, plot and save repeats across regression, classification, clustering, anomaly detection, text and time series and deploys as a Streamlit app;[32] PyTorch is taught by project, from tensors to transfer learning, LSTM forecasting, BERT and YOLO;[38] and a genetic-algorithm engine is co-evolved in pure Python across eighteen puzzles, fitness function first, rather than taken from DEAP or Pyevolve.[13]

The practice around the models has its own books, all with Python code. Feature selection methods fall into filter, wrapper and embedded families with scikit-learn, MLXtend or Feature-engine implementations;[50] seventeen common mistakes, leaking the test set, forgetting the seed, encoding categories as integers, ignoring drift, are catalogued with examples;[51] conformal prediction attaches prediction sets or intervals with guaranteed coverage to any model without retraining or distributional assumptions, taught through the MAPIE library;[52] SHAP, which shares a prediction among its features using Lloyd Shapley's 1953 values, gets a book on the theory, the estimators and the shap package's explainers;[53] forecasting begins, in a 2026 text, by asking whether the series is forecastable at all;[54] and geospatial AI applies PyTorch and torchgeo to satellite imagery on a GPU set up through conda or uv.[30]

The newest shelf is language models. One guide runs them locally with Ollama, sets up Miniconda and JupyterLab, and builds retrieval over private documents, text-to-SQL, fine-tuning, image understanding and agents, ending with the MCP and A2A protocols.[47] Another builds a terminal coding agent in plain Python with requests, python-dotenv, pytest and the standard library's subprocess, on the argument that an agent is a thermostat, a while loop with a brain, tools and a list of messages for memory; it uses an AgentStop exception for control flow, writes its tests first, and avoids every framework so that when the agent misbehaves the author can see which line did it.[27]

Python at work

Outside data science, Python is the glue of operations, hardware and production pipelines. System administrators arrive from PowerShell, and a guide for them sets Windows PowerShell 5.1 beside Python 3.6, console I/O through files and collections, on the premise that the two share more than they differ.[18] A shell function wrapping python3.13 -c is a one-line calculator, and the step up is an argparse application reading arguments or standard input.[11] Taken further, a CLI becomes a product: the Click framework, tests, wrapping Linux commands with subprocess, subcommands, Numba for speed, AWS Cloud9 and Boto3, a DockerHub image, a web service and Sphinx documentation, with the same hello-world tool in R, Bash, Go and Node for comparison.[55] Clusters have Python profiles too: a Docker and Kubernetes primer containerises a Python application among its five languages,[56] and a book on Kubernetes operators builds one in Bash, rebuilds it in Go, then rewrites it in Python with PyKube-ng and Kopf, a framework it likens to Flask.[57]

In film and games Python is the pipeline language, and a book from that seat says why: not performance but flexibility, integration with existing platforms, a low barrier to entry, ease of distribution and historical inertia; it calls Python the play-dough of scripting languages, unstructured enough to be reshaped as the production changes, and covers Rez environments, PySide interfaces, production-tracking APIs, pdb and profiling alongside the human side of the work.[41] On hardware, MicroPython runs on the Raspberry Pi Pico from the Thonny editor, and one book of tips wires up a peripheral per chapter, from servos and sensors to displays and a Prometheus exporter over Wi-Fi.[58] The full-size Raspberry Pi is the cheapest Python computer,[3] enough to run an object-orientation book's examples,[21] and a teacher's guide pairs Python with Scratch for physical computing in the classroom.[59] Security uses the language from the other side: scripts with requests and Selenium that brute-force, traverse directories and inject scripts against a supplied vulnerable machine, each paired with its fix.[36]

Sources

Every source is a Leanpub book. The note after each says which part of it was read; where no sample was available, only the public description and table of contents were used.

  1. 1.
    100 Page Python Intro, Sundeep Agarwal: Short, introductory guide for the Python programming language Free sample: preface and conventions (Python 3.13.0), installation, online tools, a first program, IDEs and the REPL, and the start of the numeric types. 2024. Free sample: PDF · EPUB
  2. 2.
    The Python Apprentice, Robert Smallshire, Austin Bingham, Sixty North Free sample: the welcome chapter on what Python is (typing, duck typing, bytecode, implementations, Python 2 and 3, the chapter plan) and the start of the classes chapter. 2022. Free sample: PDF · EPUB
  3. 3.
    Python 101, Michael Driscoll: 2nd Edition Free sample: introduction to the second edition (Python 3.8) and chapter 1 on installing Python, distributions, Android, iOS, the Raspberry Pi and the alternative implementations. 2021. Free sample: PDF · EPUB
  4. 4.
    A Hands-On Introduction to Essential Python Libraries and Frameworks (With Code Samples), Murat Durmus Free sample: a brief history of Python, the full contents, and the pandas, scikit-learn and SHAP entries. 2023. Free sample: PDF
  5. 5.
    The Python Tutorial 2.7 - unofficial, Yeradis P. Barbosa Marrero Description and table of contents: the official Python 2.7 tutorial repackaged as an ebook. 2014.
  6. 6.
    How to Tango with Django 1.9/1.10/1.11, Leif Azzopardi, David Maxwell: A beginners guide to Python/Django Free sample: chapter 1 on the book's approach, the technologies, and Rango's design brief with its architecture, wireframes, URL mappings and data model; the start of chapter 2 on the development environment. 2018. Free sample: PDF · EPUB
  7. 7.
    ReportLab - PDF Processing with Python, Michael Driscoll Free sample: introduction, virtual environments and pip, dependencies and installation, configuration, and the start of chapter 1 on points and the canvas. 2019. Free sample: PDF · EPUB
  8. 8.
    Build applications in Python the anti textbook, Suraj Description and table of contents: a short free Python 3 introduction ending in a command-line todo manager. 2019.
  9. 9.
    Creating GUI Applications with wxPython, Michael Driscoll Free sample: introduction (Python 3.7, wxPython 4, installation, IDEs) and chapter 1 on frames, panels, the main loop, classes and the start of event handling. 2020. Free sample: PDF · EPUB
  10. 10.
    Understanding Python re(gex)?, Sundeep Agarwal: Example based guide to mastering Python regular expressions Free sample: preface and conventions (Python 3.13.1), why regular expressions are needed, the chapter plan, and the introduction to the re module. 2025. Free sample: PDF · EPUB
  11. 11.
    Practice Python Projects, Sundeep Agarwal: Beginner to Intermediate level projects inspired by real world use cases Free sample: preface and conventions (Python 3.13.3), and the command-line calculator project from python -c and the REPL through sys.argv, eval and argparse. 2025. Free sample: PDF · EPUB
  12. 12.
    Discrete Mathematics for Computer Science, Marie Brodsky, Alexander Golovnev, Alexander S. Kulikov, Vladimir Podolskii, Alexander Shen Free sample: the About the Book chapter, including why the book uses Python, and the contents of its four parts. 2026. Free sample: PDF
  13. 13.
    Genetic Algorithms with Python, Clinton Sheppard Free sample: preface, the introduction to genetic algorithms and fitness, why Python and why no third-party engine, and the start of the password project. 2019. Free sample: PDF
  14. 14.
    Beginner's Python Cheat Sheets, Eric Matthes Free sample: the overview sheet (variables, lists, tuples, conditionals, dictionaries, input, loops, functions, classes, files, exceptions, the Zen of Python) and the lists sheet. 2021. Free sample: PDF
  15. 15.
    15 Cheat Sheet Collection in Python + Git + NumPy + ML + Mindset, Finxter: Easy + Quick Learning with Finxter's Best Cheat Sheets Free sample: the keywords sheet, the basic data types sheet and the complex data structures sheet. 2021. Free sample: PDF
  16. 16.
    Coffee Break Python Slicing, Finxter: 24 Workouts to Master Slicing in Python, Once and for All Description and table of contents: Python slicing taught through rated puzzles. 2019.
  17. 17.
    Coffee Break Python, Finxter: 50 Workouts to Kickstart Your Rapid Code Understanding in Python Description and table of contents: fifty Python puzzles with an Elo-style skill rating. 2019.
  18. 18.
    PowerShell Guide to Python, Prateek Singh: A Comparative Approach to Learn two Scripting Languages at once. Fast! Free sample: introduction, about the book, and the console input and output chapter with PowerShell and Python side by side. 2019. Free sample: PDF · EPUB
  19. 19.
    Learn Python With No Programming Experience: Why, How, and When to Use Functions, Jean Paul Knight Free sample: the chapter on why functions are needed. 2018. Free sample: PDF · EPUB
  20. 20.
    Intermediate Python, Obi Ike-Nwosu Free sample: the glossary on names, namespaces, scopes, eval and exec, and the start of the object-oriented programming chapter on class statements and class objects. 2016. Free sample: PDF · EPUB
  21. 21.
    Object Oriented Programming with Python, Ashwin Pajankar, Sushant Garg: Learn essentials of OOP with Python 3 Free sample: preface, chapter plan and front matter. 2017. Free sample: PDF · EPUB
  22. 22.
    The Python Journeyman, Robert Smallshire, Austin Bingham, Sixty North Description and table of contents: the second volume of the Sixty North trilogy on core Python 3. 2021.
  23. 23.
    The Python Master, Robert Smallshire, Austin Bingham, Sixty North Description and table of contents: the third volume, on the object model's advanced machinery. 2021.
  24. 24.
    Inside The Python Virtual Machine, Obi Ike-Nwosu Description and table of contents: how CPython compiles and executes code, from source to the evaluation loop. 2024.
  25. 25.
    Python 201, Michael Driscoll: Intermediate Python Free sample: chapter 1 on argparse and chapter 2 on the collections module; table of contents for the rest. 2018. Free sample: PDF · EPUB
  26. 26.
    The Smartest Way to Learn Python Regular Expressions, Finxter, Zohaib Riaz, Lukas Rieger: Learn the Best-Kept Productivity Secret of Code Masters Description and table of contents: regular expressions in Python, a chapter per feature with videos and puzzles. 2020. Free sample: PDF
  27. 27.
    Build Your Own Coding Agent, J. Owen: The Zero-Magic Guide to AI Agents in Pure Python Free sample: preface, chapter 1 on the agent loop, the Agent class, its tests and the main loop, and the start of chapter 2 on the first API call. 2026. Free sample: PDF · EPUB
  28. 28.
    QuantLib Python Cookbook, Luigi Ballabio, Goutham Balaraman Free sample: the note on Python and C++, the notebook conventions, and chapter 1 on the Date, Period, Calendar and Schedule classes. 2026. Free sample: PDF · EPUB
  29. 29.
    Introduction to GIS Programming, Qiusheng Wu: A Practical Python Guide to Open Source Geospatial Tools Free sample: the contents, including the software setup part on conda, uv and Visual Studio Code. 2026. Free sample: PDF
  30. 30.
    GeoAI with Python, Qiusheng Wu: A Practical Guide to Open-Source Geospatial AI Free sample: the contents, including the setup chapter on GPUs, Miniconda, PyTorch and uv. 2026. Free sample: PDF
  31. 31.
    Production Ready Data Science, Khuyen Tran: From Prototyping to Production with Python Free sample: preface, the list of chapters and tools, and chapter 1 on version control for data science. 2025. Free sample: PDF · EPUB
  32. 32.
    Simplifying Machine Learning with PyCaret, Giannis Tolios: A Low-code Approach for Beginners and Experts! Free sample: preface, about the book (PyCaret 3.0.0, JupyterLab), a brief introduction to machine learning, and the start of the regression chapter. 2023. Free sample: PDF · EPUB
  33. 33.
    Clean Architectures in Python, Leonardo Giordani: A practical approach to better software design Description and table of contents: the clean architecture built up through one Python application with Flask, SQLAlchemy and MongoDB. 2023.
  34. 34.
    Jupyter Notebook 101, Michael Driscoll Description and table of contents: the Jupyter Notebook from creation and sharing to extensions, widgets, debugging and other kernels. 2018.
  35. 35.
    Tango With Django 2, Leif Azzopardi and David Maxwell, David Maxwell: A beginner's guide to web development with Django 2. Free sample: chapter 1 on the book's approach, the technologies, and Rango's design brief and data model. 2020. Free sample: PDF · EPUB
  36. 36.
    Python For Hackers, Shantnu Tiwari Free sample: the directory traversal attack on a Flask file route and the cross-site scripting attack and its prevention. 2021. Free sample: PDF · EPUB
  37. 37.
    Hacker's Guide to Machine Learning with Python, Venelin Valkov: Hands-on guide to solving real-world Machine Learning problems with Scikit-Learn, TensorFlow 2, and Keras Free sample: the end-to-end project, from loading and exploring Airbnb data through preprocessing and a Keras model to a Flask API on App Engine. 2020. Free sample: PDF · EPUB
  38. 38.
    Get SH*T Done with PyTorch, Venelin Valkov: Solve Real-World Machine Learning Problems Description and table of contents: ten PyTorch projects from a first network to BERT, FastAPI and YOLO. 2020.
  39. 39.
    Event Sourcing in Python, John Bywater: Event-oriented analysis and design with applications Description and table of contents: a pattern language for event-sourced applications in Python, companion to the eventsourcing library. 2026.
  40. 40.
    Create GUI Applications with Python & Qt5 (5th Edition, PyQt5), Martin Fitzpatrick: The hands-on guide to building desktop apps with Python. Description: desktop applications with PyQt5, from a first window to packaging. 2022.
  41. 41.
    Practical Python for Production under Pressure, Alex Telford: Managing the insanity that is developing pipelines alongside a production at full speed Free sample: introduction on why Python is the pipeline language of film and games, and the chapter on frontline tools, code debt and workload. 2025. Free sample: PDF · EPUB
  42. 42.
    Introduction to Japanese Natural Language Processing, Masato Hagiwara, Paul O'Leary McCann Free sample: chapter 2 on tokenisation with fugashi and unidic-lite and the automatic fuseji project. 2026. Free sample: PDF
  43. 43.
    Effective Pandas, Tom Augspurger Free sample: introduction and the chapter on indexing with .loc and .iloc, SettingWithCopy and chained indexing, and MultiIndexes. 2016. Free sample: PDF
  44. 44.
    Spatial Data Management with DuckDB, Qiusheng Wu: From SQL Basics to Advanced Geospatial Analytics Free sample: the contents, including the chapters on installing the DuckDB command line and Python client and on first queries. 2026. Free sample: PDF
  45. 45.
    TLDR: Data Structures and Algorithms, John G: From Knowing Python to Cracking Leetcode Patterns Free sample: the hash tables chapter, from the motel-manager analogy to sets and dictionaries in Python, and the contents of the linked-list chapter. 2026. Free sample: PDF
  46. 46.
    Introduction to Data Engineering, Daniel Beach: Learn the skills needed to break into Data Engineering. Description and table of contents: a concepts-first introduction to data engineering. 2023.
  47. 47.
    Generative AI with local LLM, Shamim Bhuiyan, Timur Isachenko: A comprehensive roadmap for building AI-Driven applications with local LLMs Free sample: preface with the seven-stage learning path and chapter outline, and the opening of chapter 1 on running language models locally. 2025. Free sample: PDF · EPUB
  48. 48.
    Hands-On Machine Learning from Scratch, Venelin Valkov: Develop a Deeper Understanding of Machine Learning Models by Implementing Them from Scratch in Python Free sample: K-means clustering for colour palettes and naive Bayes sentiment analysis, implemented from scratch. 2019. Free sample: PDF · EPUB
  49. 49.
    Machine Learning Pipeline, Hisham El-Amir: Experience Gain Description and table of contents: a machine learning pipeline in Python by stage, from cleaning to models. 2019.
  50. 50.
    Feature Selection in Machine Learning, Soledad Galli, PhD: Over 20 methods to select the most predictive features and build simpler, faster, and more reliable machine learning models. Description and table of contents: filter, wrapper and embedded feature selection methods with Python implementations. 2026.
  51. 51.
    MOST COMMON MISTAKES IN MACHINE LEARNING AND HOW TO AVOID THEM: With Examples in Python, Enrique Garcia-Ceja Description: seventeen common machine learning mistakes with Python examples. 2025.
  52. 52.
    Introduction To Conformal Prediction With Python, Christoph Molnar: A Short Guide For Quantifying Uncertainty Of Machine Learning Models Free sample: summary, preface, who the book is for, the contents, and the start of chapter 4 on why uncertainty quantification is needed. 2026. Free sample: PDF
  53. 53.
    Interpreting Machine Learning Models With SHAP, Christoph Molnar: A Guide With Python Examples And Theory On Shapley Values Free sample: copyright page and the contents of all twenty chapters. 2026. Free sample: PDF
  54. 54.
    Mastering Modern Time Series Forecasting, Valery Manokhin: A Comprehensive Guide to Statistical, Machine Learning, and Deep Learning Models in Python Free sample: the opening of chapter 2 on the forecastability of time series. 2026. Free sample: PDF
  55. 55.
    Python Command Line Tools, Noah Gift, Alfredo Deza: Design powerful apps with Click Free sample: the chapter headings for the Click, testing, shell, cloud and documentation chapters, and chapter 10 comparing a hello-world tool in R, Bash, Go and Node. 2020. Free sample: PDF · EPUB
  56. 56.
    Learn Kubernetes & Docker - .NET Core, Java, Node.JS, PHP or Python, Arnaud Weil: Be ready to create and run your containerized and orchestrated application next week. Description and table of contents: Docker and Kubernetes with language profiles including Python. 2021.
  57. 57.
    The little book of Kubernetes Operators, Oz Tiram: Learn how to write a Kubernetes Operator from scratch using Go Language and Python. Free sample: introduction, the first operator in Bash, the Go project layout, debugging, and the contents including the Python rewrite with PyKube-ng and Kopf. 2025. Free sample: PDF
  58. 58.
    Raspberry Pi Pico Tips and Tricks, Malcolm Maclean Description and table of contents: the Raspberry Pi Pico in MicroPython, one peripheral per chapter. 2024.
  59. 59.
    Build, Think, & Create with Raspberry Pi in the Classroom, Michael C. Renne: A Teacher Toolkit Full Of Practical Advice and Curriculum Connections Description and table of contents: Raspberry Pi for teachers, with Scratch and Python for physical computing. 2016.

Further reading

Other books in the library on the same ground, not cited above.

  • Python Made Simpler, Nagachinmay K N A fourteen-page beginner's introduction that explains variables, types and loops through household analogies. 2025. Free sample: PDF
  • Course Analytics - Wrangling FutureLearn Data With Python and R, Tony Hirst Recipes in Python with pandas, and in R, for reporting on FutureLearn course data. 2016.
  • A QuantLib Guide, Luigi Ballabio: An introduction to the usage of the QuantLib library A tutorial-style guide to the QuantLib finance library, collecting the author's earlier material. 2026.
  • Discrete Mathematical Algorithm, and Data Structure, Sanjib Sinha: Major Components of Mathematics, and Computer Science Explained with the help of C, C++, PHP, Java, C#, Python, and Dart Discrete mathematics taught beside data structures, with examples in Python and six other languages. 2026.
  • Raspberry Pi Computing: Analog Measurement, Malcolm Maclean: Measure, record and present data using analog sensors with a Raspberry Pi computer A Raspberry Pi project that wires an analog light sensor, records readings on a schedule and serves them through a small API. 2020.
  • Raspberry Pi Computing: Ultrasonic Distance Measurement, Malcolm Maclean: Measure, record and present distance using an ultrasonic distance sensor with a Raspberry Pi computer The same author's ultrasonic distance measurement project on the Raspberry Pi. 2020.
  • Raspberry Pi Computing: Gas Sensors, Malcolm Maclean The same author's gas sensor project on the Raspberry Pi. 2020.

This is an article created from the free samples of 39 Leanpub books and the descriptions and tables of contents of 20 more. We're building these articles to provide you, the Leanpub reader, with a good jumping-off point to discover more Leanpub books that are interesting and relevant to you. We never use material which is paid-only when building these articles: we only use material which is already free on Leanpub. However, Leanpub authors can opt out from inclusion in articles from their book settings page.

Updated October 2026.

In the Leanpub store: 643 books · 8 courses in the Python category · also filed under Django, Flask, FastAPI, Django Ninja API, Numerical Computation

All topics