Hitchhiking Python Book

    imageHi, habrozhiteli! We published a book compiled on the basis of the online manual of the same name and containing the achievements of many professionals and enthusiasts who know what Python is and what you want from it.

    This guide is not intended to teach you the Python language (we will provide links to many good resources that will help you with this), but rather is a (peremptory) expert guide that discusses the popular tools and best practices of our community. The audience of this book is diverse - from beginners to mid-level Python programmers who either want to contribute to the development of open source software (software), or start a career or create a company and are going to write in Python (however, for ordinary Python users as well Part I and chapter 5) will be useful.

    In the first part of the book, we’ll talk about how to choose a text editor or interactive development environment that works for you (for example, readers who often use the Java language may prefer Eclipse with a built-in Python plugin). In addition, other interpreters are considered that satisfy those needs for which you could not even imagine that Python could handle it (for example, there is an implementation of MycroPython based on the ARM Cortex-M4 chip). The second part demonstrates the “Python” style of code example allocation adopted by the open source community. We hope this style inspires you to explore in depth and experiment with open source. Part 3 briefly reviews the wide list of libraries most commonly used in the Python community,

    Excerpt from a book. Continuous integration

    No one will describe the process of continuous integration better than Martin Fowler.

    Fowler advocates the use of good manners in software design. He is one of the main proponents of continuous integration . This quote is taken from his article on continuous integration. He led a series of workshops on development through testing and on extreme development , along with David Heinemeier Hansson (creator of Ruby on Rails) and Kent Beck, initiator of the extreme programming movement (XP), one of whose main principles is is a continuous development).

    The three most popular tools for continuous integration at the moment are Travis-CI, Jenkins, and Buildbot (listed in the following sections). They are often used with Tox, a Python tool for managing virtualenv and command line tests. Travis helps you work with multiple Python interpreters on the same platform, while Jenkins (the most popular) and Buildbot (written in Python) can manage assemblies on multiple machines. Many also use Buildout (discussed in the Buildout section of the Isolation Tools section of Chapter 3) and Docker (discussed in the Docker section in the same place) to quickly and frequently build complex environments for battery tests.

    Tox. ToxIs an automation tool that provides the functionality for packaging, testing, and deploying software written in Python from a console or continuous integration server. It is a common command-line tool for management and testing, which provides the following functions:

    • checking that all packages are correctly installed for different versions and interpreters of Python;
    • running tests in each environment, configuring selected testing tools;
    • acts as a frontend for continuous integration servers, reducing the pattern and combining tests for continuous integration and tests for the shell.

    You can install Tox with pip:
    $ pip install tox

    System administration

    The tools shown in this section are designed to monitor and manage systems (server automation, system monitoring, and flow control).


    Travis-CI is a distributed continuous integration server that allows you to create tests for open source projects for free. Provides several workflows that run Python tests, and seamlessly integrates with GitHub. You can even tell him to leave comments for your inclusion requests if this particular set of changes breaks the assembly. Therefore, if you host your code on GitHub, Travis-CI is a great way to start using continuous integration. Travis-CI can collect your code in a virtual machine running Linux, OS X, or iOS.

    To get started, add the file in the extension .travis.yml to your repository. The following code is an example of its contents:
    language: python
       - "2.6"
       - "2.7"
       - "3.3"
       - "3.4"
    script: python tests/test_all_of_the_units.py
          - master

    This code tells you to test your project for all listed versions of Python by running the specified script, the assembly will be performed only for the master branch. There are many options available, such as notifications, previous and next steps, and many others . In order to use Tox, along with Travis-CI, Tox add the script to your repository and change the line with construction script: ; the file should look like this:
    - pip install tox
    - tox

    To activate testing for your project, go to the site and log in using your GitHub account. Next, activate your project in the profile settings, and you are ready to work. From now on, tests for your project will run after each code is submitted to GitHub.


    Jenkins CI is an extensible continuous integration engine and is currently considered the most popular. Runs on Windows, Linux, and OS X and can be connected to "every existing source code management tool." Jenkins is a Java servlet (the equivalent of WSGI applications in Java) that comes with its own servlet container, which allows you to run it with the java --jar jenkins.war command . For more information, see the Jenkins installation instructions; the Ubuntu page contains information on how to host Jenkins based on reverse Apache or Nginx proxies.

    You interact with Jenkins using the dashboard or its RESTful API1 based on HTTP (for example, athttp: // myServer: 8080 / api ), which means that you can use HTTP to communicate with Jenkins from remote machines. For example, take a look at the Jenkins Dashboard for Apache or Pylons .

    To interact with the Jenkins API in Python, python-jenkins , created by the OpenStack2 team, is most commonly used . Most Python users configure Jenkins to run a Tox script as part of the build process. For more information, see the documentation at Jenkins Tox for more information , as well as the Jenkins setup guide for working with multiple machines.


    Buildbot is a Python system designed to automate a compilation / testing cycle that checks for code changes. Looks like Jenkins in that it asks the version control system manager for changes, builds and tests your code on several computers according to your instructions (it has built-in support for Tox), and then tells you what happened. It runs on the Twisted web server. If you need an example of what the web interface will look like, take a look at Chromium 's public buildbot dashboard .

    Since Buildbot is written in pure Python, it can be installed using pip:
    $ pip install buildbot

    Version 0.9 has a REST API , but it is still in beta testing, so you cannot use it unless you explicitly specify the version number (for example, pip install buildbot == ). Buildbot has a reputation for being the most powerful and sophisticated continuous integration tool. Refer to this excellent guide to get started with it .

    About Authors

    Kenneth Reitz is the owner of the Python product at Heroku and Fellow at the Python Software Foundation. He is widely known for his open source projects, and especially for Requests: HTTP for Humans.

    Tanya Schlusser takes care of her mother, who has Alzheimer's disease, works as an independent consultant, using metrics to make strategic decisions. She spent many hours training students and corporate clients to work with data.

    »More information on the book can be found on the publisher’s website
    » Table of Contents
    » Excerpt

    For Savory Agents 25% off coupon - Python

    Also popular now: