Hands-On Enterprise Application Development with Python

Book description

Architect scalable, reliable, and maintainable applications for enterprises with Python

Key Features

  • Explore various Python design patterns used for enterprise software development
  • Apply best practices for testing and performance optimization to build stable applications
  • Learn about different attacking strategies used on enterprise applications and how to avoid them

Book Description

Dynamically typed languages like Python are continuously improving. With the addition of exciting new features and a wide selection of modern libraries and frameworks, Python has emerged as an ideal language for developing enterprise applications. Hands-On Enterprise Application Development with Python will show you how to build effective applications that are stable, secure, and easily scalable.

The book is a detailed guide to building an end-to-end enterprise-grade application in Python. You will learn how to effectively implement Python features and design patterns that will positively impact your application lifecycle. The book also covers advanced concurrency techniques that will help you build a RESTful application with an optimized frontend. Given that security and stability are the foundation for an enterprise application, you'll be trained on effective testing, performance analysis, and security practices, and understand how to embed them in your codebase during the initial phase. You'll also be guided in how to move on from a monolithic architecture to one that is service oriented, leveraging microservices and serverless deployment techniques.

By the end of the book, you will have become proficient at building efficient enterprise applications in Python.

What you will learn

  • Understand the purpose of design patterns and their impact on application lifecycle
  • Build applications that can handle large amounts of data-intensive operations
  • Uncover advanced concurrency techniques and discover how to handle a large number of requests in production
  • Optimize frontends to improve the client-side experience of your application
  • Effective testing and performance profiling techniques to detect issues in applications early in the development cycle
  • Build applications with a focus on security
  • Implement large applications as microservices to improve scalability

Who this book is for

If you're a developer who wants to build enterprise-grade applications, this book is for you. Basic to intermediate-level of programming experience with Python and database systems is required to understand the concepts covered in this book.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Enterprise Application Development with Python
  3. About Packt
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. 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
  6. Using Python for Enterprise
    1. Technical requirements
    2. Recent developments in Python
      1. Dropping backward compatibility
      2. It's all Unicode
      3. Support for type hinting
    3. Where Python shines
      1. The requirements of enterprise IT
      2. Python in the enterprise ecosystem
    4. Introducing BugZot – a RESTful bug tracker
    5. Gathering requirements before development
      1. Asking for the user requirements
      2. Categorizing the requirements
      3. Prioritizing the requirements
      4. Generating the software requirement specification document
    6. Summary
    7. Questions
    8. Further reading
  7. Design Patterns – Making a Choice
    1. Technical Requirements
    2. Design patterns
      1. Classification of design patterns
      2. Defining the choice of design patterns
    3. Object-oriented Python
      1. The basic OOP principles
        1. Encapsulation
        2. Composition
        3. Inheritance
          1. Multiple inheritance in Python
          2. Method resolution order in multiple inheritance
          3. Utilizing mixins
        4. Abstract base classes
      2. Metaclasses
    4. The Singleton pattern
      1. The __call__ magic method
    5. The Factory pattern
    6. The Model-View-Controller pattern
      1. Controller
      2. Model
      3. View
    7. Summary
    8. Questions
  8. Building for Large-Scale Database Operations
    1. Technical requirements
    2. Database and object relational mappers
      1. Setting up SQLAlchemy
    3. Building optimal database models
      1. Issues with our model definition
      2. Optimizing our models
        1. Taking advantage of indexes
    4. Maintaining database consistency
      1. Utilizing transactions to maintain consistency
    5. Understanding lazy loading versus eager loading
      1. Using relationships
      2. Lazy loading
      3. Eager loading
      4. Optimizing data loading
    6. Utilizing caching
      1. Caching at the database level
      2. Caching at the block level
      3. Using user-level caching
    7. Summary
    8. Questions
  9. Dealing with Concurrency
    1. Technical requirements
    2. The need for concurrency
      1. Concurrency in GUI applications
      2. Concurrency in enterprise applications
    3. Concurrent programming with Python
      1. Concurrency with multithreading
        1. Thread synchronization
          1. Re-entrant locks
          2. Condition variables
        2. Common pitfalls with multithreading
          1. Race conditions
          2. Deadlocks
      2. The story of GIL
      3. Concurrency with multiprocessing
        1. Python multiprocessing module
          1. Synchronizing processes
    4. Summary
    5. Questions
  10. Building for Large-Scale Request Handling
    1. Technical requirements
    2. The problems of accommodating increased concurrency
      1. The multiple options to scale up
    3. Engineering the application for scalability
      1. Controlling the concurrency
      2. Using thread pools for handling incoming connections
    4. Asynchronous programming with AsyncIO
      1. AsyncIO terminology
        1. Event loop
        2. Co-routines
        3. Tasks
      2. Writing a simple Python AsyncIO program
      3. Implementing a simple socket server with AsyncIO
    5. Boosting the application concurrency
      1. Running behind a reverse proxy
        1. Improved security
        2. Improved connection handling
        3. Resource caching
        4. Serving static resources
    6. Summary
    7. Questions
  11. Example – Building BugZot
    1. Technical requirements
    2. Defining the requirements
    3. Entering the development phase
      1. Setting up the development environment
        1. Setting up the database
        2. Setting up the virtual environment
        3. Structuring our project
      2. Initializing the Flask project
      3. Creating the configuration
      4. Developing database models
        1. Migrating the database models
      5. Building the views
        1. Developing the index view
        2. Getting the index view to render
        3. Building the user registration view
    4. Deploying for concurrent access
      1. Setting up Gunicorn
      2. Setting up Nginx as reverse proxy
      3. Establishing communication between Nginx and Gunicorn
    5. Summary
    6. Questions
  12. Building Optimized Frontends
    1. Technical requirements
    2. The need for optimizing frontends
      1. Components of an optimized frontend
      2. What causes frontend issues
    3. Optimizing the frontend
      1. Optimizing resources
      2. Fetching CSS in parallel by avoiding CSS imports
      3. Bundling JavaScript
    4. Utilizing client-side caching
      1. Setting application-wide cache control
      2. Setting request level cache control
    5. Utilizing web storage
      1. Working with local web storage
      2. Working with session storage
    6. Summary
    7. Questions
  13. Writing Testable Code
    1. Technical requirements
    2. The importance of testing
      1. The different kinds of testing
        1. Unit testing
        2. Integration testing
    3. Building an application with testing in mind
      1. Test-driven development
    4. Writing unit tests
      1. Writing unit tests with Python unittest
      2. Writing unit tests with pytest
        1. Let's set up pytest
        2. Writing our first test with pytest
        3. Writing functional tests with pytest
    5. Summary
    6. Questions
  14. Profiling Applications for Performance
    1. Technical requirements
    2. Behind the scenes of performance bottlenecks
      1. Looking at the causes of performance bottlenecks
    3. Probing an application for performance issues
      1. Writing performance benchmarks
        1. Writing our first benchmark
        2. Writing an API benchmark
      2. Doing component-level performance analysis
        1. Measuring slow operations with timeit
        2. Profiling with cProfile
        3. Profiling for memory usage with memory_profiler
      3. Collecting live performance data
        1. Logging performance metrics
    4. Avoiding performance bottlenecks
    5. Summary
    6. Questions
  15. Securing Your Application
    1. Technical requirements
    2. Enterprise application security
      1. The importance of enterprise security
      2. Challenges in system security
    3. Taking a look at the attack vectors
      1. Security issues with native applications
      2. Security issues with web applications
    4. Security anti-patterns
      1. Not filtering user input
      2. Storing Sensitive Data Unencrypted
      3. Ignoring bound-checking
      4. Not keeping the libraries updated
      5. Giving full privileges of the database to a single user
    5. Improving your application's security
    6. Summary
    7. Questions
    8. Further reading
  16. Taking the Microservices Approach
    1. Technical requirements
    2. The shift toward microservices
      1. Monolithic development model versus microservices
      2. Advantages of the microservices architecture
      3. Guidelines for microservice development
      4. Service-level agreements in microservices
    3. Building your first microservices application
      1. The user microservice
      2. The to-do manager service
    4. Service discovery in microservices
      1. Service registry inside microservices
      2. Client-side service discovery
      3. Server-side service discovery
    5. API gateways in microservices
    6. Asynchronous communication in microservices
      1. Message queues for microservices communication
    7. Summary
    8. Questions
    9. Further reading
  17. Testing and Tracing in Microservices
    1. Technical requirements
    2. Testing in the microservices world
      1. Unit testing in microservices
      2. Functionality testing in microservices
      3. Integration testing in microservices
      4. End-to-end testing in microservices
      5. Scalability testing
      6. Challenges in microservices testing
    3. Tracing requests inside microservices
      1. The OpenTracing standard
      2. Implementing tracing inside ToDo manager
      3. Distributed tracing
        1. Benefits of distributed tracing
    4. Summary
    5. Questions
  18. Going Serverless
    1. Technical requirements
    2. The serverless approach to application development
    3. Components of serverless architecture
      1. Backend as a service
      2. Function as a service
        1. The restrictions on state management
        2. Restrictions on execution times
        3. Executing functions inside FaaS
      3. API gateways in the serverless architecture
    4. Understanding the execution of a serverless application
      1. Cold-starting a function
      2. Hot-starting a function
    5. Building our first serverless application
      1. A quick introduction to Apache OpenWhisk
      2. Setting up the development environment
      3. Building our configuration file
      4. Integrating with the GitHub API
      5. Getting the code ready to run with OpenWhisk
      6. Taking the final steps toward deployment
      7. Deploying to OpenWhisk
    6. Understanding the execution of application Inside Openwhisk
    7. Advantages of going serverless
    8. Summary
    9. Questions
    10. Further reading
  19. Deploying to the Cloud
    1. Technical requirements
    2. Deploying enterprise applications
    3. Making a choice about the deployment strategy
      1. The different deployment strategies
        1. Recreated deployments
        2. Rolling deployments
        3. Blue/green deployments
        4. Canary deployments
        5. A/B deployments
        6. Shadow deployments
    4. Making a choice of infrastructure
      1. The traditional infrastructure
      2. Containerized approach toward application packaging
      3. The move toward the cloud
    5. The different types of cloud deployments
      1. Private clouds
      2. Public clouds
      3. Hybrid clouds
    6. Summary
    7. Questions
  20. Enterprise Application Integration and its Patterns
    1. Technical requirements
    2. The need for EAI
      1. Point-to-point integration
      2. Moving towards EAI
    3. The traditional approach to EAI
    4. The introduction of the ESB
    5. Patterns in EAI
      1. Integration patterns
        1. Mediation pattern
        2. Federation pattern
      2. Access patterns
        1. Asynchronous access patterns
        2. Synchronous access patterns
    6. Issues in EAI
    7. Summary
    8. Questions
  21. Microservices and Enterprise Application Integration
    1. Technical requirements
    2. Microservices and the changing EAI landscape
    3. Challenges of traditional EAI in microservices
      1. Point-to-point integration of microservices
      2. Integrating microservices using the ESB
    4. Utilizing API gateways for the integration of microservices
    5. Transformation of the ESB
    6. Rethinking EAI in microservices
    7. Summary
    8. Questions
  22. Assessment
    1. Chapter 1
      1. Answer 1
      2. Answer 2
      3. Answer 3
      4. Answer 4
      5. Answer 5
    2. Chapter 2
      1. Answer 1
      2. Answer 2
      3. Answer 3
    3. Chapter 3
      1. Answer 1
      2. Answer 2
      3. Answer 3
      4. Answer 4
    4. Chapter 4
      1. Answer 1
      2. Answer 2
      3. Answer 3
      4. Answer 4
      5. Answer 5
    5. Chapter 5
      1. Answer 1
      2. Answer 2
      3. Answer 3
      4. Answer 4
    6. Chapter 6
      1. Answer 1
      2. Answer 2
      3. Answer 3
      4. Answer 4
    7. Chapter 7
      1. Answer 1
      2. Answer 2
      3. Answer 3
    8. Chapter 8
      1. Answer 1
      2. Answer 2
      3. Answer 3
      4. Answer 4
    9. Chapter 9
      1. Answer 1
      2. Answer 2
      3. Answer 3
      4. Answer 4
      5. Answer 5
    10. Chapter 10
      1. Answer 1
      2. Answer 2
      3. Answer 3
      4. Answer 4
    11. Chapter 11
      1. Answer 1
      2. Answer 2
      3. Answer 3
      4. Answer 4
      5. Answer 5
    12. Chapter 12
      1. Answer 1
      2. Answer 2
      3. Answer 3
      4. Answer 4
    13. Chapter 13
      1. Answer 1
      2. Answer 2
      3. Answer 3
      4. Answer 4
    14. Chapter 14
      1. Answer 1
      2. Answer 2
      3. Answer 3
      4. Answer 4
    15. Chapter 15
      1. Answer 1
      2. Answer 2
      3. Answer 3
    16. Chapter 16
      1. Answer 1
      2. Answer 2
      3. Answer 3
  23. Other Books You May Enjoy
    1. Leave a review – let other readers know what you think

Product information

  • Title: Hands-On Enterprise Application Development with Python
  • Author(s): Saurabh Badhwar
  • Release date: December 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789532364