GitHub - shikharkumar13/Python-Programming-Code: This repository covers end to end Python needed for Data Analysis, Data Science and building AI Applications
Repository navigation
Python-Programming-CodePublic
About
This repository covers end to end Python needed for Data Analysis, Data Science and building AI Applications
Topics
api exception-handling functions-python iterators modules object-oriented-programming python-data-structures virtualenvResources
Readme ActivityStars
40 starsWatchers
3 watchingForks
10 forks Report repositoryBranches
Tags
Go to Branches page Go to Tags page
Latest commit
History
125 Commits
View commit history for this file.
Folders and files
Repository files navigation
Python Programming Series
A complete, runnable Python course in 20 chapters, taking a reader from their first literal to a tested, packaged data pipeline. Built as the language prerequisite for data science, machine learning and AI engineering work.
Read the companion articles: https://shikharkumar13.github.io/Python-Programming-Code/index.html
Contents
- What this is
- Getting started
- Curriculum
- Repository layout
- Reproducible outputs
- Authoring tools
- Where to go next
What this is
20 Jupyter notebooks, 1,686 cells, 907 of them executable, with every output committed and verified. Chapters 1 to 10 also have a long-form written article published as a static site.
The material is designed around three principles:
Nothing is asserted without being demonstrated. Where a chapter warns you about
something, a cell shows it happening. The regex that silently matches a commented-out
HTML element, the assert that vanishes under python -O, the @contextmanager
whose cleanup never runs, the price parser that returns None and explodes three
frames later: each is executed, not described.
Every chapter is unlocked by the one before it. Decorators open on the timer written by hand in chapter 7. Generators open on the file read line by line in chapter 10. The capstone in chapter 20 uses essentially all nineteen.
The examples are real. Branded, concrete scenarios rather than foo and bar,
and from chapter 17 onward, real HTTP requests against a live API.
Who it is for
Anyone who wants a solid Python foundation before moving into data work. Chapters 1 to 10 assume no programming background. Chapters 11 to 20 assume you have finished them.
What you need
Python 3.10 or newer, and Jupyter. Chapters 1 to 16 use the standard library only; chapters 17 and 18 add two packages, and chapter 19 introduces two development tools.
Getting started
git clone https://github.com/shikharkumar13/Python-Programming-Code.git cd Python-Programming-Code python3 -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate python3 -m pip install -r requirements.txt # only needed from chapter 17 python3 -m pip install jupyterlab jupyter lab "1. Introduction to Python.ipynb"
Chapters 1 to 16 need nothing installed beyond Jupyter itself. If you would rather read than run, chapters 1 to 10 are published as articles at the link above.
Dependencies
| Package | Needed by | Why |
|---|---|---|
requests |
17, 18 | HTTP requests |
beautifulsoup4 |
18 | HTML parsing |
pytest |
19 | Running the tests that chapter writes |
mypy |
19 | Checking the type hints that chapter writes |
Installing them is itself the worked example in chapter 11, which covers virtual
environments and requirements.txt before anything depends on them.
Curriculum
Part I: The language (chapters 1 to 10)
From literals to file I/O. No third-party packages, no installation.
| # | Chapter | Cells | Notebook | Article |
|---|---|---|---|---|
| 1 | Introduction to Python Literals, variables, naming, memory model, interpreted vs compiled |
64 | open | read |
| 2 | Lists, Tuples and Strings Sequence types, slicing, mutability, string methods, formatting |
171 | open | read |
| 3 | Sets and Dictionaries Hashing, set algebra, dictionary methods, comprehensions |
73 | open | read |
| 4 | Operators Arithmetic, comparison, logical, bitwise, identity, precedence |
100 | open | read |
| 5 | Conditional Statements and Loops if/elif/else, for, while, break, continue, nesting |
102 | open | read |
| 6 | Functions in Python Definition, arguments, defaults, *args, **kwargs, scope, return |
53 | open | read |
| 7 | Types of Functions in Python enumerate, zip, map/filter/reduce, lambda, recursion |
54 | open | read |
| 8 | Object-Oriented Programming Classes, four pillars, five inheritance types, MRO, duck typing |
74 | open | read |
| 9 | Exception Handling Hierarchy, try/except/else/finally, chaining, assert, logging |
54 | open | read |
| 10 | File Handling Modes, seek/tell, os, pathlib, CSV, JSON, shutil |
67 | open | read |
Part II: How Python is actually written (chapters 11 to 16)
The constructs you meet the moment you read real code, and the tooling around them.
| # | Chapter | Cells | Notebook | Article |
|---|---|---|---|---|
| 11 | Modules and Virtual Environments import machinery, writing modules, packages, terminal, venv, pip, import errors, layout |
105 | open | read |
| 12 | Iterators and Generators Iterator protocol, yield, laziness, generator expressions |
108 | open | read |
| 13 | Closures and Decorators First-class functions, closures, @, functools, decorator factories |
102 | open | read |
| 14 | Context Managers __enter__/__exit__, @contextmanager, suppress, ExitStack |
98 | open | read |
| 15 | The Standard Library Toolkit collections, itertools, functools, datetime |
127 | open | read |
| 16 | Regular Expressions Raw strings, character classes, groups, greedy vs lazy, re.escape |
97 | open | read |
Part III: Working with real data (chapters 17 to 20)
Getting data from the network, and shipping code that survives contact with it.
| # | Chapter | Cells | Notebook | Article |
|---|---|---|---|---|
| 17 | Working with APIs HTTP verbs, status codes, timeouts, retries, keys, pagination |
69 | open | read |
| 18 | Web Scraping robots.txt, BeautifulSoup, selectors, tables, encoding, ethics |
65 | open | read |
| 19 | Writing Reliable Code Type hints, mypy, docstrings, logging, pytest, tracebacks |
59 | open | read |
| 20 | Capstone Project End-to-end pipeline: package, tests, validation, CSV and JSON output |
44 | open |
Repository layout
.
├── 1. Introduction to Python.ipynb the 20 chapters, in order
├── ...
├── 20. Capstone Project.ipynb
│
├── docs/ the published site (GitHub Pages)
│ ├── index.html series index
│ └── N_topic.html one self-contained article per chapter
│
├── sample_data/ frozen fixtures, committed on purpose
│ ├── github_repo.json real API responses, trimmed (ch. 17)
│ ├── issues_page_*.json paginated responses (ch. 17)
│ └── shop_page_*.html hand-written pages to parse (ch. 18)
│
├── tools/ authoring helpers, not a build step
│ ├── nb_edit.py byte-identical notebook round-trip
│ ├── series.py the canonical chapter list and nav
│ ├── verify_outputs.py re-execute and diff committed outputs
│ ├── highlight.py Pygments spans for article code blocks
│ └── requirements.txt what the tools need (readers never do)
│
└── requirements.txt
Each article in docs/ is a single self-contained HTML file: inline stylesheet, inline
SVG icon sprite, inline script, and code blocks pre-highlighted with Pygments. The only
external dependency is Google Fonts. Nothing is generated from the notebooks; the
articles are hand-written expansions of the same material.
Reproducible outputs
Notebook outputs are committed, which means a wrong one reaches a reader looking exactly like a right one. Every committed output in this repository has been executed and checked:
python3 tools/verify_outputs.py --all # re-run all 20, diff every output python3 tools/verify_outputs.py "4. Operators.ipynb"
The script executes each notebook in a fresh kernel and compares the result against what is on disk. It reports mismatches without touching the file. All 20 chapters pass from a clean checkout and pass again on a repeat run, which is the check that catches the outputs that are only correct the second time you run them.
Run it twice. Python randomises string hashing per process, so anything printing a
set's iteration order passes one run and fails the next. The same applies to id(),
memory addresses in a default repr, and timings. None of them belong in a committed
output, and two runs is what finds them.
52 cells carry a skip-verify tag because their output legitimately differs from run
to run or machine to machine: live network calls, timestamps, memory addresses,
interactive input(), set iteration order, installed package versions, and file paths on the computer running it. They still execute; only the comparison is skipped, and the reason is
recorded per cell.
Offline by default
The network chapters read committed fixtures from sample_data/, so chapters 17 and 18
produce the same output every time and work with no internet. A small number of clearly
marked cells make a real request, and the notebooks say so up front.
Authoring tools
tools/ holds four helpers used to write and maintain the material. They are not a build
step: docs/ is hand-authored and nothing in it is generated from the notebooks.
Their dependencies are kept out of the reader's requirements.txt:
python3 -m pip install -r tools/requirements.txt # nbformat, nbclient, ipykernel, pygments + the course packages
| Tool | Purpose |
|---|---|
nb_edit.py |
Loads and saves notebooks byte-identically (indent=1, ensure_ascii=False), so a two-line change produces a two-line diff instead of rewriting every line of the file. |
series.py |
The single ordered list of chapters. Regenerates the prev/next navigation across every article, and skips chapters whose article does not exist yet so no page ever links to a 404. |
verify_outputs.py |
Executes a notebook in a fresh kernel and reports outputs that no longer reproduce. |
highlight.py |
Emits the Pygments token spans that the article code blocks require. |
python3 tools/series.py list # chapter list, and what exists so far python3 tools/series.py nav --check # report prev/next drift across articles python3 tools/series.py nav # rewrite the nav blocks
nav exits non-zero if a published article has no nav block for it to rewrite;
nav --check also exits non-zero on drift, so either can gate a commit.
Where to go next
This repository ends where the data work begins. Chapter 20 produces a clean, tidy CSV and hands it over deliberately:
- This repository. The Python language, and getting data in.
- NumPy, pandas and exploratory analysis. The dataset from chapter 20 is the file you walk in with.
- Machine learning, MLOps and AI engineering. Everything that needs a trained model or a deployed service.
Notes
- Chapters are self-contained enough to read out of order, but each one builds on the vocabulary of the last, and later chapters reference earlier ones by number.
- The demo directories that chapters write while running (
file_handling_demo/,module_demo/,api_demo/and others) are gitignored.sample_data/is the exception and is committed on purpose. - Articles for chapters 11 to 20 are in progress. The notebooks are complete.
About
This repository covers end to end Python needed for Data Analysis, Data Science and building AI Applications