Python for Geeks

Book description

Take your Python skills to the next level to develop scalable, real-world applications for local as well as cloud deployment

Key Features

  • All code examples have been tested with Python 3.7 and Python 3.8 and are expected to work with any future 3.x release
  • Learn how to build modular and object-oriented applications in Python
  • Discover how to use advanced Python techniques for the cloud and clusters

Book Description

Python is a multipurpose language that can be used for multiple use cases. Python for Geeks will teach you how to advance in your career with the help of expert tips and tricks.

You'll start by exploring the different ways of using Python optimally, both from the design and implementation point of view. Next, you'll understand the life cycle of a large-scale Python project. As you advance, you'll focus on different ways of creating an elegant design by modularizing a Python project and learn best practices and design patterns for using Python. You'll also discover how to scale out Python beyond a single thread and how to implement multiprocessing and multithreading in Python. In addition to this, you'll understand how you can not only use Python to deploy on a single machine but also use clusters in private as well as in public cloud computing environments. You'll then explore data processing techniques, focus on reusable, scalable data pipelines, and learn how to use these advanced techniques for network automation, serverless functions, and machine learning. Finally, you'll focus on strategizing web development design using the techniques and best practices covered in the book.

By the end of this Python book, you'll be able to do some serious Python programming for large-scale complex projects.

What you will learn

  • Understand how to design and manage complex Python projects
  • Strategize test-driven development (TDD) in Python
  • Explore multithreading and multiprogramming in Python
  • Use Python for data processing with Apache Spark and Google Cloud Platform (GCP)
  • Deploy serverless programs on public clouds such as GCP
  • Use Python to build web applications and application programming interfaces
  • Apply Python for network automation and serverless functions
  • Get to grips with Python for data analysis and machine learning

Who this book is for

This book is for intermediate-level Python developers in any field who are looking to build their skills to develop and manage large-scale complex projects. Developers who want to create reusable modules and Python libraries and cloud developers building applications for cloud deployment will also find this book useful. Prior experience with Python will help you get the most out of this book.

Publisher resources

Download Example Code

Table of contents

  1. Python for Geeks
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
  6. Section 1: Python, beyond the Basics
  7. Chapter 1: Optimal Python Development Life Cycle
    1. Python culture and community
    2. Different phases of a Python project
    3. Strategizing the development process
      1. Iterating through the phases
      2. Aiming for MVP first
      3. Strategizing development for specialized domains
    4. Effectively documenting Python code
      1. Python comments
      2. Docstring
      3. Functional or class-level documentation
    5. Developing an effective naming scheme
      1. Methods
      2. Variables
      3. Constant
      4. Classes
      5. Packages
      6. Modules
      7. Import conventions
      8. Arguments
      9. Useful tools
    6. Exploring choices for source control
      1. What does not belong to the source control repository?
    7. Understanding strategies for deploying the code
      1. Batch development
    8. Python development environments
      1. IDLE
      2. Sublime Text
      3. PyCharm
      4. Visual Studio Code
      5. PyDev
      6. Spyder
    9. Summary
    10. Questions
    11. Further reading
    12. Answers
  8. Chapter 2: Using Modularization to Handle Complex Projects
    1. Technical requirements
    2. Introduction to modules and packages
    3. Importing modules
      1. Using the import statement
      2. Using the __import__ statement
      3. Using the importlib.import_module statement
      4. Absolute versus relative import
    4. Loading and initializing a module
      1. Standard modules
    5. Writing reusable modules
    6. Building packages
      1. Naming
      2. Package initialization file
      3. Building a package
    7. Accessing packages from any location
    8. Sharing a package
      1. Building a package as per the PyPA guidelines
      2. Installing from the local source code using pip
      3. Publishing a package to Test PyPI
      4. Installing the package from PyPI
    9. Summary
    10. Questions
    11. Further reading
    12. Answers
  9. Chapter 3: Advanced Object-Oriented Python Programming
    1. Technical requirements
    2. Introducing classes and objects
      1. Distinguishing between class attributes and instance attributes
      2. Using constructors and destructors with classes
      3. Distinguishing between class methods and instance methods
      4. Special methods
    3. Understanding OOP principles
      1. Encapsulation of data
      2. Encompassing data and actions
      3. Hiding information
      4. Protecting the data
      5. Using traditional getters and setters
      6. Using property decorators
      7. Extending classes with inheritance
      8. Simple inheritance
      9. Multiple inheritance
    4. Polymorphism
      1. Method overloading
      2. Method overriding
      3. Abstraction
    5. Using composition as an alternative design approach
    6. Introducing duck typing in Python
    7. Learning when not to use OOP in Python
    8. Summary
    9. Questions
    10. Further reading
    11. Answers
  10. Section 2: Advanced Programming Concepts
  11. Chapter 4: Python Libraries for Advanced Programming
    1. Technical requirements
    2. Introducing Python data containers
      1. Strings
      2. Lists
      3. Tuples
      4. Dictionaries
      5. Sets
    3. Using iterators and generators for data processing
      1. Iterators
      2. Generators
    4. Handling files in Python
      1. File operations
      2. Using a context manager
      3. Operating on multiple files
    5. Handling errors and exceptions
      1. Working with exceptions in Python
      2. Raising exceptions
      3. Defining custom exceptions
    6. Using the Python logging module
      1. Introducing core logging components
      2. Working with the logging module
      3. What to log and what not to log
    7. Summary
    8. Questions
    9. Further reading
    10. Answers
  12. Chapter 5: Testing and Automation with Python
    1. Technical requirements
    2. Understanding various levels of testing
      1. Unit testing
      2. Integration testing
      3. System testing
      4. Acceptance testing
    3. Working with Python test frameworks
      1. Working with the unittest framework
      2. Working with the pytest framework
    4. Executing TDD
      1. Red
      2. Green
      3. Refactor
    5. Introducing automated CI
    6. Summary
    7. Questions
    8. Further reading
    9. Answers
  13. Chapter 6: Advanced Tips and Tricks in Python
    1. Technical requirements
    2. Learning advanced tricks for using functions
      1. Introducing the counter, itertools, and zip functions for iterative tasks
      2. Using filters, mappers, and reducers for data transformations
      3. Learning how to build lambda functions
      4. Embedding a function within another function
      5. Modifying function behavior using decorators
    3. Understanding advanced concepts with data structures
      1. Embedding a dictionary inside a dictionary
      2. Using comprehension
    4. Introducing advanced tricks with pandas DataFrame
      1. Learning DataFrame operations
      2. Learning advanced tricks for a DataFrame object
    5. Summary
    6. Questions
    7. Further reading
    8. Answers
  14. Section 3: Scaling beyond a Single Thread
  15. Chapter 7: Multiprocessing, Multithreading, and Asynchronous Programming
    1. Technical requirements
    2. Understanding multithreading in Python and its limitations
      1. What is a Python blind spot?
      2. Learning the key components of multithreaded programming in Python
      3. Case study – a multithreaded application to download files from Google Drive
    3. Going beyond a single CPU – implementing multiprocessing
      1. Creating multiple processes
      2. Sharing data between processes
      3. Exchanging objects between processes
      4. Synchronization between processes
      5. Case study – a multiprocessor application to download files from Google Drive
    4. Using asynchronous programming for responsive systems
      1. Understanding the asyncio module
      2. Distributing tasks using queues
      3. Case study – asyncio application to download files from Google Drive
    5. Summary
    6. Questions
    7. Further reading
    8. Answers
  16. Chapter 8: Scaling out Python Using Clusters
    1. Technical requirements
    2. Learning about the cluster options for parallel processing
      1. Hadoop MapReduce
      2. Apache Spark
    3. Introducing RDDs
      1. Learning RDD operations
      2. Creating RDD objects
    4. Using PySpark for parallel data processing
      1. Creating SparkSession and SparkContext programs
      2. Exploring PySpark for RDD operations
      3. Learning about PySpark DataFrames
      4. Introducing PySpark SQL
    5. Case studies of using Apache Spark and PySpark
      1. Case study 1 – Pi (π) calculator on Apache Spark
      2. Case study 2 – Word cloud using PySpark
    6. Summary
    7. Questions
    8. Further reading
    9. Answers
  17. Chapter 9: Python Programming for the Cloud
    1. Technical requirements
    2. Learning about the cloud options for Python applications
      1. Introducing Python development environments for the cloud
      2. Introducing cloud runtime options for Python
    3. Building Python web services for cloud deployment
      1. Using Google Cloud SDK
      2. Using the GCP web console
    4. Using Google Cloud Platform for data processing
      1. Learning the fundamentals of Apache Beam
      2. Introducing Apache Beam pipelines
      3. Building pipelines for Cloud Dataflow
    5. Summary
    6. Questions
    7. Further reading
    8. Answers
  18. Section 4: Using Python for Web, Cloud, and Network Use Cases
  19. Chapter 10: Using Python for Web Development and REST API
    1. Technical requirements
    2. Learning requirements for web development
      1. Web frameworks
      2. User interface
      3. Web server/application server
      4. Database
      5. Security
      6. API
      7. Documentation
    3. Introducing the Flask framework
      1. Building a basic application with routing
      2. Handling requests with different HTTP method types
      3. Rendering static and dynamic contents
      4. Extracting parameters from an HTTP request
      5. Interacting with database systems
      6. Handling errors and exceptions in web applications
    4. Building a REST API
      1. Using Flask for a REST API
      2. Developing a REST API for database access
    5. Case study– Building a web application using the REST API
    6. Summary
    7. Questions
    8. Further reading
    9. Answers
  20. Chapter 11: Using Python for Microservices Development
    1. Technical requirements
    2. Introducing microservices
    3. Learning best practices for microservices
    4. Building microservices-based applications
      1. Learning microservice development options in Python
      2. Introducing deployment options for microservices
      3. Developing a sample microservices-based application
    5. Summary
    6. Questions
    7. Further reading
    8. Answers
  21. Chapter 12: Building Serverless Functions using Python
    1. Technical requirements
    2. Introducing serverless functions
      1. Benefits
      2. Use cases
    3. Understanding the deployment options for serverless functions
    4. Learning how to build serverless functions
      1. Building an HTTP-based Cloud Function using the GCP Console
      2. Case study – building a notification app for cloud storage events
    5. Summary
    6. Questions
    7. Further reading
    8. Answers
  22. Chapter 13: Python and Machine Learning
    1. Technical requirements
    2. Introducing machine learning
    3. Using Python for machine learning
      1. Introducing machine learning libraries in Python
      2. Best practices of training data with Python
    4. Building and evaluating a machine learning model
      1. Learning about an ML model building process
      2. Building a sample ML model
      3. Evaluating a model using cross-validation and fine tuning hyperparameters
      4. Saving an ML model to a file
    5. Deploying and predicting an ML model on GCP Cloud
    6. Summary
    7. Questions
    8. Further reading
    9. Answers
  23. Chapter 14: Using Python for Network Automation
    1. Technical requirements
    2. Introducing network automation
      1. Merits and challenges of network automation
      2. Use cases
    3. Interacting with network devices
      1. Protocols for interacting with network devices
      2. Interacting with network devices using SSH-based Python libraries
      3. Interacting with network devices using NETCONF
    4. Integrating with network management systems
      1. Using location services endpoints
      2. Getting an authentication token
      3. Getting network devices and an interface inventory
      4. Updating the network device port
    5. Integrating with event-driven systems
      1. Creating subscriptions for Apache Kafka
      2. Processing events from Apache Kafka
      3. Renewing and deleting a subscription
    6. Summary
    7. Questions
    8. Further reading
    9. Answers
    10. Why subscribe?
  24. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts

Product information

  • Title: Python for Geeks
  • Author(s): Muhammad Asif
  • Release date: October 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781801070119