O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Python Programming Blueprints

Book Description

How to build useful, real-world applications in the Python programming language

About This Book

  • Deliver scalable and high-performing applications in Python.
  • Delve into the great ecosystem of Python frameworks and libraries through projects that you will build with this book.
  • This comprehensive guide will help you demonstrate the power of Python by building practical projects.

Who This Book Is For

This book is for software developers who are familiar with Python and want to gain hands-on experience with web and software development projects. A basic knowledge of Python programming is required.

What You Will Learn

  • Learn object-oriented and functional programming concepts while developing projects
  • The dos and don'ts of storing passwords in a database
  • Develop a fully functional website using the popular Django framework
  • Use the Beautiful Soup library to perform web scrapping
  • Get started with cloud computing by building microservice and serverless applications in AWS
  • Develop scalable and cohesive microservices using the Nameko framework
  • Create service dependencies for Redis and PostgreSQL

In Detail

Python is a very powerful, high-level, object-oriented programming language. It's known for its simplicity and huge community support. Python Programming Blueprints will help you build useful, real-world applications using Python.

In this book, we will cover some of the most common tasks that Python developers face on a daily basis, including performance optimization and making web applications more secure. We will familiarize ourselves with the associated software stack and master asynchronous features in Python. We will build a weather application using command-line parsing. We will then move on to create a Spotify remote control where we'll use OAuth and the Spotify Web API. The next project will cover reactive extensions by teaching you how to cast votes on Twitter the Python way. We will also focus on web development by using the famous Django framework to create an online game store. We will then create a web-based messenger using the new Nameko microservice framework. We will cover topics like authenticating users and, storing messages in Redis.

By the end of the book, you will have gained hands-on experience in coding with Python.

Style and approach

With a hands-on approach, Python Programming Blueprints guides you through diverse real-life projects to get you started; it presents most aspects of the Python programming language gradually, going from basic to advanced topics.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Python Programming Blueprints
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  5. Contributors
    1. About the authors
    2. About the reviewers
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  7. Implementing the Weather Application
    1. Setting up the environment
    2. Core functionality
      1. Loading parsers dynamically
      2. Creating the application's model
      3. Fetching data from the weather website
    3. Getting the user's input with ArgumentParser
    4. Creating the parser
      1. Getting today's weather forecast
        1. Adding helper methods
        2. Implementing today's weather forecast
      2. Getting five- and ten-day weather forecasts
      3. Getting the weekend weather forecast
    5. Summary
  8. Creating a Remote-Control Application with Spotify
    1. Setting up the environment
    2. Creating a Spotify app
    3. The application's configuration
      1. Creating a configuration file
      2. Implementing a configuration file reader
    4. Authenticating with Spotify's web API
      1. Implementing the client credentials flow
      2. Implementing the authorization code flow
      3. Authorizing our application with authorization code flow
    5. Querying Spotify's web API
    6. Creating the player
      1. Adding menus for albums and track selection
      2. Implementing the menu panel
      3. Creating the DataManager class
      4. Time to listen to music!
    7. Summary
  9. Casting Votes on Twitter
    1. Setting up the environment
    2. Creating a Twitter application
    3. Adding the configuration file
    4. Performing authentication
      1. Creating the Flask application
        1. Creating the application routes
    5. Building the Twitter voting application
      1. Enhancing our code
    6. Summary
  10. Exchange Rates and the Currency Conversion Tool
    1. Setting up the environment
    2. Creating the API wrapper
    3. Adding the database helper class
    4. Creating the command line parser
      1. Creating the currency enumeration
      2. Creating the command line parser
        1. Basic validation
    5. Adding the application's entry point
    6. Testing our application
    7. Summary
  11. Building a Web Messenger with Microservices
    1. TempMessenger Goals
    2. Requirements
    3. What is Nameko?
      1. RPCs
      2. How Nameko uses AMQP
      3. RabbitMQ
        1. Starting a RabbitMQ container
      4. Installing Python requirements
    4. Creating your first Nameko microservice
      1. Making a call to our service
    5. Unit-testing a Nameko microservice
    6. Exposing HTTP entrypoints
    7. Integration testing Nameko microservices
    8. Storing messages
      1. An introduction to Redis
        1. Starting a Redis container
        2. Installing the Python Redis client
        3. Using Redis
    9. Nameko Dependency Providers
      1. Adding a Redis Dependency Provider
        1. Designing the Client
        2. Creating the Dependency Provider
        3. Creating our Message Service
        4. Putting it all together
    10. Saving messages
      1. Adding a save message method to our Redis client
      2. Adding a save message RPC
    11. Retrieving all messages
      1. Adding a get all messages method to our Redis client
      2. Adding a get all messages RPC
      3. Putting it all together
    12. Displaying messages in the web browser
      1. Adding a Jinja2 Dependency Provider
        1. Creating the template renderer
      2. Creating our homepage template
      3. Creating the Dependency Provider
      4. Making a HTML response
      5. Putting it all together
    13. Sending messages via POST requests
      1. Adding a send messages POST request
      2. Adding an AJAX POST request in jQuery
    14. Expiring messages in Redis
    15. Sorting messages
    16. Browser polling for messages
      1. Polling with JavaScript
    17. Summary
  12. Extending TempMessenger with a User Authentication Microservice
    1. TempMessenger goals
    2. Requirements
    3. Creating a Postgres dependency
      1. Starting a Postgres Docker container
      2. Creating the user model
      3. Creating the user dependency
    4. Creating users
      1. Creating the User Service
    5. Securely storing passwords in the database
      1. Using Bcrypt
      2. Hashing our user passwords
      3. Handling duplicate users
    6. Authenticating users
      1. Retrieving users from the database
      2. Authenticating a user's password
    7. Splitting out the services
    8. Creating a Flask server
    9. Web sessions
      1. Creating a sign-up page
      2. Logging users out
      3. Logging users in
    10. Prepending the email to our messages
    11. Summary
  13. Online Video Game Store with Django
    1. Setting up the development environment
      1. Installing Node.js
    2. Creating a new Django project
    3. Exploring the Django project's structure
      1. Diving into the SQLite
      2. Looking at the project's package directory
    4. Creating the project's main app
    5. Installing client-side dependencies
    6. Adding login and logout views
      1. Testing the login/logout forms
    7. Creating new users
      1. Creating the views of the user creation
    8. Creating the game data model
      1. Creating the price list data model
      2. Creating the game list and details page
      3. Adding list games views
    9. Creating the shopping cart model
      1. Creating the shopping cart form
      2. Creating the shopping cart view
      3. Adding items to the cart
    10. Summary
  14. Order Microservice
    1. Setting up the environment
    2. Creating the service models
    3. Creating the model's managers
    4. Learning to test
      1. Creating the test files
      2. Testing the cancel order function 
      3. Testing the get all orders function
      4. Getting customer's incomplete orders
      5. Getting customer's completed orders
      6. Getting orders by status
      7. Getting orders by period
      8. Setting the order's next status
      9. Setting the order's status
    5. Creating the order model serializer
    6. Creating the views
      1. Adding views
    7. Setting up the service URLs
    8. Integration with the game online store
      1. Testing the integration
    9. Deploying to AWS
      1. Modifying the settings.py file
      2. Deploying the order service
    10. Summary
  15. Notification Serverless Application
    1. Setting up the environment
    2. Setting up the Amazon Web Services CLI
    3. Configuring a Simple Email Service
      1. Registering the emails
    4. Creating an S3 bucket
    5. Implementing the notification service
      1. Email templates
    6. Deploying the application with Zappa
    7. Restricting access to the API's endpoints
    8. Modifying the order service
    9. Testing all the pieces together
    10. Summary
  16. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think