- Ramping up with professional Python
- Learning the language
- Exercises
- Ramping up with specific libraries
- Topics
- Reference and other lists
The goal of this documentation is to help you become a productive Python developer.
It assumes that those skills will be used in a professional environment. It includes concrete exercises, because the best way to learn is by doing. It focuses on real-world, applied documentation that will help your programming on a day-to-day basis.
This doc assumes programming knowledge and experience.
If you're also interested in generic programming best practices, I've compiled a list of professional programming resources.
First, Why Beginners Should Learn Python
Here are some free books:
- Learn Python the Hard Way: slow introduction, suitable for people with limited programming language experience.
- Dive Into Python: much faster introduction to Python, a bit outdated but will get you ramped up really fast, especially if you've learned a number of programming language in the past. There's a version for Python 3 as well.
- Official Tutorial: Python's official doc is really good, highly recommended read.
The Python Guide has some other good resources.
If you're coming from another language, read this article about the ten myths of enterprise Python.
If you want to review algorithms at the same time, you can use Problem Solving with Algorithms and Data Structures using Python by Bradley N. Miller, David L. Ranum.
Other resources include (prefer the one listed above):
To find other list of resources:
Learn Python online – A curated list of courses on Python
I wrote some introductory material to advanced Python:
- Read the Introduction to advanced Python article.
- Check out the advanced Python presentation I authored on Slideshare.
- Muhammad Yasoob Ullah Khalid, Intermediate Python
- Luciano Ramalho, Fluent Python
- Dusty Phillips, Python 3 Object-Oriented Programming
- Brett Slatkin, Effective Python: 59 Specific Ways to Write Better Python
First things first, let's get code styling out of the way. Make sure you've read an memorized PEP8 (code style, more readable version here) and PEP257 (docstring style). Those two code styles are applied by almost all major Python applications and libraries. Use flake8 and autopep8.
What is called "idiomatic Python" might feel magical at first, especially if you don't know Python. I'd recommend getting your hands dirty with some real world Python code. Try to wander around the code, opening random files. Run the tutorial with a debugger to follow the flow and understand what's going on.
- bottle.py: bottle is a web framework. It's a great resource because it's in all in whole file! Recommended reading. You can even print it.
- flask: another web framework, one of the best. Reading its code is highly recommended as well.
You can find other ideas on this hacker news thread.
I feel it's more important to understand the vision behind Python's design, than to know specific Python idioms. The Zen of Python will let you understand the fundamental reasoning behind each idiom.
>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
Learning idiomatic Python:
- The Hitchhiker’s Guide to Python
- Idiomatic Python
- What the heck does “pythonic” mean?
- Elements of Python style
List of books:
The best way to learn is to do.
- Create a virtual environment with
virtualenv
. - Create a virtual environment with
virtualenvwrapper
tools. - Fix a bug in one of the Python packages listed in the Python guide.
- Create a server exposing a Thrift API.
- Take inspiration from this list of Raspberry Pi projects on reddit
- Discover Flask
- Build a lock library for redis.
- Build a cache library for redis.
- Build an API for next bus departure time.
- Build an ORM for a SQL database.
- Build a command line parser.
- Build a template engine.
- Build a static site generator.
- Build an HTTP library.
- Clone one of those games
- Solve some of the Project Euler problems
- Write a game using pyarcade
Reddit's dailyprogrammer subreddit has some good exercises as well.
Another great way to learn Python is by contributing to one of the numerous open source libraries. Coding is not something that is to be learn in isolation, and you'll learn great valuable insights from the code review you'll get from those communities. You can look for tickets (e.g. Github issues) for Python libraries you're using, or find some in the list below, or pick one of the libraries listed in Awesome Python. Make sure you pick a library where the tickets are not too involved, and where the community is still alive (i.e. there's recent merged pull requests).
Regardless of whether you use them, those tutorials introduce you to important concept and good design patterns, so they're highly recommended:
- Do the Flask tutorial.
- Watch the SQLAlchemy introduction video. It lasts 3 hours but is extremely insightful, and introduces to some great object oriented patterns.
Other great SQLAlchemy resources include:
Other specific libraries that are very often used in professional environments:
- Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well.
- Tornado is a Python web framework and asynchronous networking library.
- Alembic is a lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python.
- Jinja is a full featured template engine for Python. It has full unicode support, an optional integrated sandboxed execution environment, widely used and BSD licensed.
- Doubles is a Python package that provides test doubles for use in automated tests.
- Mock is a library for testing in Python. It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used.
- pytest is a test framework.
Awesome Python provides a great list of third party libraries.
- Celery best practices, Balthazar
- General introduction: Python debugging tools
- A better debugger: pudb
- Debugging Python Like a Boss
- Design patterns explained
- Python 3 Patterns, Recipes and Idioms
- Decorators in 12 steps
- Design pattern templates in Python (Github)
I maintain a list of antipatterns on another repo. This is a highly recommended read.
- Why Python is Slow: Looking Under the Hood
- The internals of Python string interning
- Python Data structures
- Read the guide
- setup.py vs. requirements.txt: this is an important gotcha for any library developer.
- Open Sourcing a Python Project the Right Way
- Pipfile: a
Pipfile
, and its relatedPipfile.lock
, are a new (and much better!) replacement for pip's requirements.txt files.
- Profiling Python using cProfile: a concrete case
- cProfile module documentation
- Example cProfile session
- A guide to analyzing Python performance
- RunSnakeRun is a small GUI utility that allows you to view (Python) cProfile or Profile profiler dumps in a sortable GUI view.
- SnakeViz is a browser based graphical viewer for the output of Python’s cProfile module.
- Using qcachegrind to visualize profiling data
- Python quirks
- Hidden features of Python
- 30 Python Language Features and Tricks You May Not Know About
- A collection of Python "wat" moments
- satwikkansal/wtfpython: a collection of interesting, subtle, and tricky Python snippets
Half of coding time is usually spent writing tests. Yet how to write tests efficiently is very rarely taught at school - even though it came make a huge difference in engineering productivity and quality.
First, make sure you're familiar with the different kind of testing strategies laid out in Testing Strategies in a Microservices Architecture (Martin Fowler).
Then, read some of those articles:
- Mock yourself, not your tests: great articles about the danger of mocking, and better unit testing strategies.
- Solving Unicode Problems in Python 2.7
- Unicode Howto in Python 3 (official Python documentation).
- The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
- Best Python Resources
- Awesome Python
- PyCon 2015
- Invent With Python, Further Reading: Intermediate Python Resources
- Good to great Python reads
There are two main newsletters for Python, which mostly cover the same things:
You can also checkout the Python subreddit.
Read this up on my professional programming doc.
If you want to get in touch, checkout my website.