> For the complete documentation index, see [llms.txt](https://yo-sarawut.gitbook.io/tutorials/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yo-sarawut.gitbook.io/tutorials/books/python/the-hitchhikers-guide-to-python.md).

# The Hitchhiker’s Guide to Python

![enter image description here](https://images-na.ssl-images-amazon.com/images/I/51oqxVFGbBL._SX377_BO1,204,203,200_.jpg)

Greetings, Earthling! Welcome to The Hitchhiker’s Guide to Python.

**This is a living, breathing guide.** If you’d like to contribute, [fork us on GitHub](https://github.com/realpython/python-guide)!

This handcrafted guide exists to provide both novice and expert Python developers a best practice handbook to the installation, configuration, and usage of Python on a daily basis.

This guide is **opinionated** in a way that is almost, but not quite, entirely *unlike* Python’s official documentation. You won’t find a list of every Python web framework available here. Rather, you’ll find a nice concise list of highly recommended options.

Note

The use of **Python 3** is *highly* preferred over Python 2. Consider upgrading your applications and infrastructure if you find yourself *still* using Python 2 in production today. If you are using Python 3, congratulations — you are indeed a person of excellent taste. —*Kenneth Reitz*

Let’s get started! But first, let’s make sure you know where your towel is.

### Getting Started with Python

New to Python? Let’s properly setup up your Python environment:

* [Picking a Python Interpreter (3 vs 2)](https://docs.python-guide.org/starting/which-python/)
  * [The State of Python (3 & 2)](https://docs.python-guide.org/starting/which-python/#the-state-of-python-3-2)
  * [Recommendations](https://docs.python-guide.org/starting/which-python/#recommendations)
  * [So…. 3?](https://docs.python-guide.org/starting/which-python/#so-3)
  * [Implementations](https://docs.python-guide.org/starting/which-python/#implementations)
* Properly Install Python on your system:

> - [Properly Installing Python](https://docs.python-guide.org/starting/installation/)
> - [Installing Python 3 on Mac OS X](https://docs.python-guide.org/starting/install3/osx/)
> - [Installing Python 3 on Windows](https://docs.python-guide.org/starting/install3/win/)
> - [Installing Python 3 on Linux](https://docs.python-guide.org/starting/install3/linux/)
> - [Installing Python 2 on Mac OS X](https://docs.python-guide.org/starting/install/osx/)
> - [Installing Python 2 on Windows](https://docs.python-guide.org/starting/install/win/)
> - [Installing Python 2 on Linux](https://docs.python-guide.org/starting/install/linux/)

* Using Virtualenvs with Pipenv:

> - [Pipenv & Virtual Environments](https://docs.python-guide.org/dev/virtualenvs/)
>   * [Make sure you’ve got Python & pip](https://docs.python-guide.org/dev/virtualenvs/#make-sure-you-ve-got-python-pip)
>   * [Installing Pipenv](https://docs.python-guide.org/dev/virtualenvs/#installing-pipenv)
>   * [Installing packages for your project](https://docs.python-guide.org/dev/virtualenvs/#installing-packages-for-your-project)
>   * [Using installed packages](https://docs.python-guide.org/dev/virtualenvs/#using-installed-packages)
>   * [Next steps](https://docs.python-guide.org/dev/virtualenvs/#next-steps)
> - [Lower level: virtualenv](https://docs.python-guide.org/dev/virtualenvs/#lower-level-virtualenv)
>   * [Basic Usage](https://docs.python-guide.org/dev/virtualenvs/#basic-usage)
>   * [Other Notes](https://docs.python-guide.org/dev/virtualenvs/#other-notes)
>   * [virtualenvwrapper](https://docs.python-guide.org/dev/virtualenvs/#virtualenvwrapper)
>   * [virtualenv-burrito](https://docs.python-guide.org/dev/virtualenvs/#virtualenv-burrito)
>   * [direnv](https://docs.python-guide.org/dev/virtualenvs/#direnv)

### Python Development Environments

This part of the guide focuses on the Python development environment, and the best-practice tools that are available for writing Python code.

* [Your Development Environment](https://docs.python-guide.org/dev/env/)
  * [Text Editors](https://docs.python-guide.org/dev/env/#text-editors)
  * [IDEs](https://docs.python-guide.org/dev/env/#ides)
  * [Interpreter Tools](https://docs.python-guide.org/dev/env/#interpreter-tools)
  * [Other Tools](https://docs.python-guide.org/dev/env/#other-tools)
* [Pipenv & Virtual Environments](https://docs.python-guide.org/dev/virtualenvs/)
  * [Make sure you’ve got Python & pip](https://docs.python-guide.org/dev/virtualenvs/#make-sure-you-ve-got-python-pip)
  * [Installing Pipenv](https://docs.python-guide.org/dev/virtualenvs/#installing-pipenv)
  * [Installing packages for your project](https://docs.python-guide.org/dev/virtualenvs/#installing-packages-for-your-project)
  * [Using installed packages](https://docs.python-guide.org/dev/virtualenvs/#using-installed-packages)
  * [Next steps](https://docs.python-guide.org/dev/virtualenvs/#next-steps)
* [Lower level: virtualenv](https://docs.python-guide.org/dev/virtualenvs/#lower-level-virtualenv)
  * [Basic Usage](https://docs.python-guide.org/dev/virtualenvs/#basic-usage)
  * [Other Notes](https://docs.python-guide.org/dev/virtualenvs/#other-notes)
  * [virtualenvwrapper](https://docs.python-guide.org/dev/virtualenvs/#virtualenvwrapper)
  * [virtualenv-burrito](https://docs.python-guide.org/dev/virtualenvs/#virtualenv-burrito)
  * [direnv](https://docs.python-guide.org/dev/virtualenvs/#direnv)
* [Further Configuration of pip and Virtualenv](https://docs.python-guide.org/dev/pip-virtualenv/)
  * [Requiring an active virtual environment for `pip`](https://docs.python-guide.org/dev/pip-virtualenv/#requiring-an-active-virtual-environment-for-pip)
  * [Caching packages for future use](https://docs.python-guide.org/dev/pip-virtualenv/#caching-packages-for-future-use)

### Writing Great Python Code

This part of the guide focuses on the best-practices for writing Python code.

* [Structuring Your Project](https://docs.python-guide.org/writing/structure/)
  * [Structure of the Repository](https://docs.python-guide.org/writing/structure/#structure-of-the-repository)
  * [Structure of Code is Key](https://docs.python-guide.org/writing/structure/#structure-of-code-is-key)
  * [Modules](https://docs.python-guide.org/writing/structure/#modules)
  * [Packages](https://docs.python-guide.org/writing/structure/#packages)
  * [Object-oriented programming](https://docs.python-guide.org/writing/structure/#object-oriented-programming)
  * [Decorators](https://docs.python-guide.org/writing/structure/#decorators)
  * [Context Managers](https://docs.python-guide.org/writing/structure/#context-managers)
  * [Dynamic typing](https://docs.python-guide.org/writing/structure/#dynamic-typing)
  * [Mutable and immutable types](https://docs.python-guide.org/writing/structure/#mutable-and-immutable-types)
  * [Vendorizing Dependencies](https://docs.python-guide.org/writing/structure/#vendorizing-dependencies)
  * [Runners](https://docs.python-guide.org/writing/structure/#runners)
  * [Further Reading](https://docs.python-guide.org/writing/structure/#further-reading)
* [Code Style](https://docs.python-guide.org/writing/style/)
  * [General concepts](https://docs.python-guide.org/writing/style/#general-concepts)
  * [Idioms](https://docs.python-guide.org/writing/style/#idioms)
  * [Zen of Python](https://docs.python-guide.org/writing/style/#zen-of-python)
  * [PEP 8](https://docs.python-guide.org/writing/style/#pep-8)
  * [Conventions](https://docs.python-guide.org/writing/style/#conventions)
* [Reading Great Code](https://docs.python-guide.org/writing/reading/)
* [Documentation](https://docs.python-guide.org/writing/documentation/)
  * [Project Documentation](https://docs.python-guide.org/writing/documentation/#project-documentation)
  * [Project Publication](https://docs.python-guide.org/writing/documentation/#project-publication)
  * [Code Documentation Advice](https://docs.python-guide.org/writing/documentation/#code-documentation-advice)
  * [Other Tools](https://docs.python-guide.org/writing/documentation/#other-tools)
* [Testing Your Code](https://docs.python-guide.org/writing/tests/)
  * [The Basics](https://docs.python-guide.org/writing/tests/#the-basics)
  * [Tools](https://docs.python-guide.org/writing/tests/#tools)
* [Logging](https://docs.python-guide.org/writing/logging/)
  * [… or Print?](https://docs.python-guide.org/writing/logging/#or-print)
  * [Logging in a Library](https://docs.python-guide.org/writing/logging/#logging-in-a-library)
  * [Logging in an Application](https://docs.python-guide.org/writing/logging/#logging-in-an-application)
* [Common Gotchas](https://docs.python-guide.org/writing/gotchas/)
  * [Mutable Default Arguments](https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments)
  * [Late Binding Closures](https://docs.python-guide.org/writing/gotchas/#late-binding-closures)
  * [Bytecode (.pyc) Files Everywhere!](https://docs.python-guide.org/writing/gotchas/#bytecode-pyc-files-everywhere)
* [Choosing a License](https://docs.python-guide.org/writing/license/)

### Scenario Guide for Python Applications

This part of the guide focuses on tool and module advice based on different scenarios.

* [Network Applications](https://docs.python-guide.org/scenarios/client/)
  * [HTTP](https://docs.python-guide.org/scenarios/client/#http)
  * [Distributed Systems](https://docs.python-guide.org/scenarios/client/#distributed-systems)
* [Web Applications & Frameworks](https://docs.python-guide.org/scenarios/web/)
  * [Context](https://docs.python-guide.org/scenarios/web/#context)
  * [Frameworks](https://docs.python-guide.org/scenarios/web/#frameworks)
  * [Web Servers](https://docs.python-guide.org/scenarios/web/#web-servers)
  * [WSGI Servers](https://docs.python-guide.org/scenarios/web/#wsgi-servers)
  * [Server Best Practices](https://docs.python-guide.org/scenarios/web/#server-best-practices)
  * [Hosting](https://docs.python-guide.org/scenarios/web/#hosting)
  * [Templating](https://docs.python-guide.org/scenarios/web/#templating)
* [HTML Scraping](https://docs.python-guide.org/scenarios/scrape/)
  * [Web Scraping](https://docs.python-guide.org/scenarios/scrape/#web-scraping)
  * [lxml and Requests](https://docs.python-guide.org/scenarios/scrape/#lxml-and-requests)
* [Command-line Applications](https://docs.python-guide.org/scenarios/cli/)
  * [Click](https://docs.python-guide.org/scenarios/cli/#click)
  * [docopt](https://docs.python-guide.org/scenarios/cli/#docopt)
  * [Plac](https://docs.python-guide.org/scenarios/cli/#plac)
  * [Cliff](https://docs.python-guide.org/scenarios/cli/#cliff)
  * [Cement](https://docs.python-guide.org/scenarios/cli/#cement)
  * [Python Fire](https://docs.python-guide.org/scenarios/cli/#python-fire)
* [GUI Applications](https://docs.python-guide.org/scenarios/gui/)
  * [Camelot](https://docs.python-guide.org/scenarios/gui/#camelot)
  * [Cocoa](https://docs.python-guide.org/scenarios/gui/#cocoa)
  * [GTk](https://docs.python-guide.org/scenarios/gui/#gtk)
  * [PyGObject aka (PyGi)](https://docs.python-guide.org/scenarios/gui/#pygobject-aka-pygi)
  * [Kivy](https://docs.python-guide.org/scenarios/gui/#kivy)
  * [PyObjC](https://docs.python-guide.org/scenarios/gui/#pyobjc)
  * [PySide](https://docs.python-guide.org/scenarios/gui/#pyside)
  * [PyQt](https://docs.python-guide.org/scenarios/gui/#pyqt)
  * [Pyjs Desktop (formerly Pyjamas Desktop)](https://docs.python-guide.org/scenarios/gui/#pyjs-desktop-formerly-pyjamas-desktop)
  * [Qt](https://docs.python-guide.org/scenarios/gui/#qt)
  * [PySimpleGUI](https://docs.python-guide.org/scenarios/gui/#pysimplegui)
  * [Toga](https://docs.python-guide.org/scenarios/gui/#toga)
  * [Tk](https://docs.python-guide.org/scenarios/gui/#tk)
  * [wxPython](https://docs.python-guide.org/scenarios/gui/#wxpython)
* [Databases](https://docs.python-guide.org/scenarios/db/)
  * [DB-API](https://docs.python-guide.org/scenarios/db/#db-api)
  * [SQLAlchemy](https://docs.python-guide.org/scenarios/db/#sqlalchemy)
  * [Records](https://docs.python-guide.org/scenarios/db/#records)
  * [PugSQL](https://docs.python-guide.org/scenarios/db/#pugsql)
  * [Django ORM](https://docs.python-guide.org/scenarios/db/#django-orm)
  * [peewee](https://docs.python-guide.org/scenarios/db/#peewee)
  * [PonyORM](https://docs.python-guide.org/scenarios/db/#ponyorm)
  * [SQLObject](https://docs.python-guide.org/scenarios/db/#sqlobject)
* [Networking](https://docs.python-guide.org/scenarios/network/)
  * [Twisted](https://docs.python-guide.org/scenarios/network/#twisted)
  * [PyZMQ](https://docs.python-guide.org/scenarios/network/#pyzmq)
  * [gevent](https://docs.python-guide.org/scenarios/network/#gevent)
* [Systems Administration](https://docs.python-guide.org/scenarios/admin/)
  * [Fabric](https://docs.python-guide.org/scenarios/admin/#fabric)
  * [Salt](https://docs.python-guide.org/scenarios/admin/#salt)
  * [Psutil](https://docs.python-guide.org/scenarios/admin/#psutil)
  * [Ansible](https://docs.python-guide.org/scenarios/admin/#ansible)
  * [Chef](https://docs.python-guide.org/scenarios/admin/#chef)
  * [Puppet](https://docs.python-guide.org/scenarios/admin/#puppet)
  * [Blueprint](https://docs.python-guide.org/scenarios/admin/#blueprint)
  * [Buildout](https://docs.python-guide.org/scenarios/admin/#buildout)
  * [Shinken](https://docs.python-guide.org/scenarios/admin/#shinken)
* [Continuous Integration](https://docs.python-guide.org/scenarios/ci/)
  * [Why?](https://docs.python-guide.org/scenarios/ci/#why)
  * [Jenkins](https://docs.python-guide.org/scenarios/ci/#jenkins)
  * [Buildbot](https://docs.python-guide.org/scenarios/ci/#buildbot)
  * [Tox](https://docs.python-guide.org/scenarios/ci/#tox)
  * [Travis-CI](https://docs.python-guide.org/scenarios/ci/#travis-ci)
* [Speed](https://docs.python-guide.org/scenarios/speed/)
  * [Context](https://docs.python-guide.org/scenarios/speed/#context)
  * [C Extensions](https://docs.python-guide.org/scenarios/speed/#id2)
  * [Concurrency](https://docs.python-guide.org/scenarios/speed/#concurrency)
* [Scientific Applications](https://docs.python-guide.org/scenarios/scientific/)
  * [Context](https://docs.python-guide.org/scenarios/scientific/#context)
  * [Tools](https://docs.python-guide.org/scenarios/scientific/#tools)
  * [Libraries](https://docs.python-guide.org/scenarios/scientific/#libraries)
  * [Resources](https://docs.python-guide.org/scenarios/scientific/#resources)
* [Image Manipulation](https://docs.python-guide.org/scenarios/imaging/)
  * [Python Imaging Library](https://docs.python-guide.org/scenarios/imaging/#python-imaging-library)
  * [Open Source Computer Vision](https://docs.python-guide.org/scenarios/imaging/#open-source-computer-vision)
* [Data Serialization](https://docs.python-guide.org/scenarios/serialization/)
  * [What is data serialization?](https://docs.python-guide.org/scenarios/serialization/#what-is-data-serialization)
  * [Flat vs. Nested data](https://docs.python-guide.org/scenarios/serialization/#flat-vs-nested-data)
  * [Serializing Text](https://docs.python-guide.org/scenarios/serialization/#serializing-text)
  * [Binary](https://docs.python-guide.org/scenarios/serialization/#binary)
  * [Protobuf](https://docs.python-guide.org/scenarios/serialization/#protobuf)
* [XML parsing](https://docs.python-guide.org/scenarios/xml/)
  * [untangle](https://docs.python-guide.org/scenarios/xml/#untangle)
  * [xmltodict](https://docs.python-guide.org/scenarios/xml/#xmltodict)
* [JSON](https://docs.python-guide.org/scenarios/json/)
  * [Parsing JSON](https://docs.python-guide.org/scenarios/json/#parsing-json)
  * [simplejson](https://docs.python-guide.org/scenarios/json/#simplejson)
* [Cryptography](https://docs.python-guide.org/scenarios/crypto/)
  * [cryptography](https://docs.python-guide.org/scenarios/crypto/#id1)
  * [GPGME bindings](https://docs.python-guide.org/scenarios/crypto/#gpgme-bindings)
* [Machine Learning](https://docs.python-guide.org/scenarios/ml/)
  * [SciPy Stack](https://docs.python-guide.org/scenarios/ml/#scipy-stack)
  * [scikit-learn](https://docs.python-guide.org/scenarios/ml/#scikit-learn)
* [Interfacing with C/C++ Libraries](https://docs.python-guide.org/scenarios/clibs/)
  * [C Foreign Function Interface](https://docs.python-guide.org/scenarios/clibs/#c-foreign-function-interface)
  * [ctypes](https://docs.python-guide.org/scenarios/clibs/#ctypes)
  * [SWIG](https://docs.python-guide.org/scenarios/clibs/#swig)
  * [Boost.Python](https://docs.python-guide.org/scenarios/clibs/#boost-python)

### Shipping Great Python Code

This part of the guide focuses on sharing and deploying your Python code.

* [Publishing Your Code](https://docs.python-guide.org/shipping/publishing/)
  * [Creating a Project Repo on GitHub](https://docs.python-guide.org/shipping/publishing/#creating-a-project-repo-on-github)
  * [When Your Project Grows](https://docs.python-guide.org/shipping/publishing/#when-your-project-grows)
* [Packaging Your Code](https://docs.python-guide.org/shipping/packaging/)
  * [Alternatives to Packaging](https://docs.python-guide.org/shipping/packaging/#alternatives-to-packaging)
  * [For Python Developers](https://docs.python-guide.org/shipping/packaging/#for-python-developers)
  * [For Linux Distributions](https://docs.python-guide.org/shipping/packaging/#for-linux-distributions)
* [Freezing Your Code](https://docs.python-guide.org/shipping/freezing/)
  * [Alternatives to Freezing](https://docs.python-guide.org/shipping/freezing/#alternatives-to-freezing)
  * [Comparison of Freezing Tools](https://docs.python-guide.org/shipping/freezing/#comparison-of-freezing-tools)
  * [Windows](https://docs.python-guide.org/shipping/freezing/#windows)
  * [OS X](https://docs.python-guide.org/shipping/freezing/#os-x)
  * [Linux](https://docs.python-guide.org/shipping/freezing/#linux)

### Additional Notes

This part of the guide, which is mostly prose, begins with some background information about Python, and then focuses on next steps.

* [Introduction](https://docs.python-guide.org/intro/duction/)
  * [About This Guide](https://docs.python-guide.org/intro/duction/#about-this-guide)
* [The Community](https://docs.python-guide.org/intro/community/)
  * [BDFL](https://docs.python-guide.org/intro/community/#bdfl)
  * [Python Software Foundation](https://docs.python-guide.org/intro/community/#python-software-foundation)
  * [PEPs](https://docs.python-guide.org/intro/community/#peps)
  * [Python Conferences](https://docs.python-guide.org/intro/community/#python-conferences)
  * [Python User Groups](https://docs.python-guide.org/intro/community/#python-user-groups)
  * [Online Communities](https://docs.python-guide.org/intro/community/#online-communities)
  * [Python Job Boards](https://docs.python-guide.org/intro/community/#python-job-boards)
* [Learning Python](https://docs.python-guide.org/intro/learning/)
  * [Beginner](https://docs.python-guide.org/intro/learning/#beginner)
  * [Intermediate](https://docs.python-guide.org/intro/learning/#intermediate)
  * [Advanced](https://docs.python-guide.org/intro/learning/#advanced)
  * [For Engineers and Scientists](https://docs.python-guide.org/intro/learning/#for-engineers-and-scientists)
  * [Miscellaneous Topics](https://docs.python-guide.org/intro/learning/#miscellaneous-topics)
  * [References](https://docs.python-guide.org/intro/learning/#references)
* [Documentation](https://docs.python-guide.org/intro/documentation/)
  * [Official Documentation](https://docs.python-guide.org/intro/documentation/#official-documentation)
  * [Read the Docs](https://docs.python-guide.org/intro/documentation/#read-the-docs)
  * [pydoc](https://docs.python-guide.org/intro/documentation/#pydoc)
* [News](https://docs.python-guide.org/intro/news/)
  * [PyCoder’s Weekly](https://docs.python-guide.org/intro/news/#pycoders-weekly)
  * [Real Python](https://docs.python-guide.org/intro/news/#real-python)
  * [Planet Python](https://docs.python-guide.org/intro/news/#planet-python)
  * [/r/python](https://docs.python-guide.org/intro/news/#r-python)
  * [Talk Python Podcast](https://docs.python-guide.org/intro/news/#talk-python-podcast)
  * [Python Bytes Podcast](https://docs.python-guide.org/intro/news/#python-bytes-podcast)
  * [Python Weekly](https://docs.python-guide.org/intro/news/#python-weekly)
  * [Python News](https://docs.python-guide.org/intro/news/#python-news)
  * [Import Python Weekly](https://docs.python-guide.org/intro/news/#import-python-weekly)
  * [Awesome Python Newsletter](https://docs.python-guide.org/intro/news/#awesome-python-newsletter)

Note

Notes defined within all diatonic and chromatic musical scales have been intentionally excluded from this list of additional notes. Additionally, this note.

Contribution notes and legal information (for those interested).

* [Contribute](https://docs.python-guide.org/notes/contribute/)
  * [Style Guide](https://docs.python-guide.org/notes/contribute/#style-guide)
  * [Todo List](https://docs.python-guide.org/notes/contribute/#todo-list)
* [License](https://docs.python-guide.org/notes/license/)
* [The Guide Style Guide](https://docs.python-guide.org/notes/styleguide/)
  * [Relevancy](https://docs.python-guide.org/notes/styleguide/#relevancy)
  * [Headings](https://docs.python-guide.org/notes/styleguide/#headings)
  * [Prose](https://docs.python-guide.org/notes/styleguide/#prose)
  * [Code Examples](https://docs.python-guide.org/notes/styleguide/#code-examples)
  * [Externally Linking](https://docs.python-guide.org/notes/styleguide/#externally-linking)
  * [Linking to Sections in The Guide](https://docs.python-guide.org/notes/styleguide/#linking-to-sections-in-the-guide)
  * [Notes and Warnings](https://docs.python-guide.org/notes/styleguide/#notes-and-warnings)
  * [TODOs](https://docs.python-guide.org/notes/styleguide/#todos)
