Python Architecture Patterns: Master API design, event-driven structures, and package management in Python
- Length: 594 pages
- Edition: 1
- Language: English
- Publisher: Packt Publishing
- Publication Date: 2022-01-12
- ISBN-10: 1801819998
- ISBN-13: 9781801819992
- Sales Rank: #520797 (See Top 100 Books)
Make the best of your test suites by using cutting-edge software architecture patterns in Python
Key Features
- Learn how to create scalable and maintainable applications
- Build a web system for micro messaging using concepts in the book
- Use profiling to find bottlenecks and improve the speed of the system
Book Description
Developing large-scale systems that continuously grow in scale and complexity requires a thorough understanding of how software projects should be implemented. Software developers, architects, and technical management teams rely on high-level software design patterns such as microservices architecture, event-driven architecture, and the strategic patterns prescribed by domain-driven design (DDD) to make their work easier.
This book covers these proven architecture design patterns with a forward-looking approach to help Python developers manage application complexity―and get the most value out of their test suites.
Starting with the initial stages of design, you will learn about the main blocks and mental flow to use at the start of a project. The book covers various architectural patterns like microservices, web services, and event-driven structures and how to choose the one best suited to your project. Establishing a foundation of required concepts, you will progress into development, debugging, and testing to produce high-quality code that is ready for deployment. You will learn about ongoing operations on how to continue the task after the system is deployed to end users, as the software development lifecycle is never finished.
By the end of this Python book, you will have developed “architectural thinking”: a different way of approaching software design, including making changes to ongoing systems.
What you will learn
- Think like an architect, analyzing software architecture patterns
- Explore API design, data storage, and data representation methods
- Investigate the nuances of common architectural structures
- Utilize and interoperate elements of patterns such as microservices
- Implement test-driven development to perform quality code testing
- Recognize chunks of code that can be restructured as packages
- Maintain backward compatibility and deploy iterative changes
Who this book is for
This book will help software developers and architects understand the structure of large complex systems and adopt architectural patterns that are scalable. Examples in the book are implemented in Python so a fair grasp of basic Python concepts is expected. Proficiency in any programming languages such as Java or JavaScript is sufficient.
Table of Contents
- Introduction to Software Architecture
- API Design
- Data Modeling
- The Data Layer
- The Twelve-Factor App Methodology
- Web Server Structures
- Event-Driven Structures
- Advanced Event-Driven Structures
- Microservices vs Monolith
- Testing and TDD
- Package Management
- Logging
- Metrics
- Profiling
- Debugging
- Ongoing Architecture
Preface Who this book is for What this book covers To get the most out of this book Get in touch Share your thoughts Introduction to Software Architecture Defining the structure of a system Division into smaller units In-process communication Conway's Law – Effects on software architecture Application example – Overview Security aspects of software architecture Summary Part I Design API Design Abstractions Using the right abstractions Leaking abstractions Resources and action abstractions RESTful interfaces A more practical definition Headers and statuses Designing resources Resources and parameters Pagination Designing a RESTful API process Using the Open API specification Authentication Authenticating HTML interfaces Authenticating RESTful interfaces Self-encoded tokens Versioning the API Why versioning? Internal versus external versioning Semantic versioning Simple versioning Frontend and backend Model View Controller structure HTML interfaces Traditional HTML interfaces Dynamic pages Single-page apps Hybrid approach Designing the API for the example Endpoints Review of the design and implementation Summary Data Modeling Types of databases Relational databases Non-relational databases Key-value stores Document stores Wide-column databases Graph databases Small databases Database transactions Distributed relational databases Primary/replica Sharding Pure sharding Mixed sharding Table sharding Advantages and disadvantages of sharding Schema design Schema normalization Denormalization Data indexing Cardinality Summary The Data Layer The Model layer Domain-Driven Design Using ORM Independence from the database Independence from SQL and the Repository pattern No problems related to composing SQL The Unit of Work pattern and encapsulating the data CQRS, using different models for read and write Database migrations Backward compatibility Relational schema changes Changing the database without interruption Data migrations Changes without enforcing a schema Dealing with legacy databases Detecting a schema from a database Syncing the existing schema to the ORM definition Summary Part II Architectural Patterns The Twelve-Factor App Methodology Intro to the Twelve-Factor App Continuous Integration Scalability Configuration The Twelve Factors Build once, run multiple times Dependencies and configurations Scalability Monitoring and admin Containerized Twelve-Factor Apps Summary Web Server Structures Request-response Web architecture Web servers Serving static content externally Reverse proxy Logging Advanced usages uWSGI The WSGI application Interacting with the web server Processes Process lifecycle Python worker Django MVT architecture Routing a request towards a View The View HttpRequest HttpResponse Middleware Django REST framework Models URL routing Views Serializer External layers Summary Event-Driven Structures Sending events Asynchronous tasks Subdividing tasks Scheduled tasks Queue effects Single code for all workers Cloud queues and workers Celery Configuring Celery Celery worker Triggering tasks Connecting the dots Scheduled tasks Celery Flower Flower HTTP API Summary Advanced Event-Driven Structures Streaming events Pipelines Preparation Base task Image task Video task Connecting the tasks Running the task Defining a bus More complex systems Testing event-driven systems Summary Microservices vs Monolith Monolithic architecture The microservices architecture Which architecture to choose A side note about similar designs The key factor – team communication Moving from a monolith to microservices Challenges for the migration A move in four acts 1. Analyze 2. Design 3. Plan 4. Execute Containerizing services Building and running an image Building and running a web service uWSGI configuration nginx configuration Start script Building and running Caveats Orchestration and Kubernetes Summary Part III Implementation Testing and TDD Testing the code Different levels of testing Unit tests Integration tests System tests Testing philosophy How to design a great test Structuring tests Test-Driven Development Introducing TDD into new teams Problems and limitations Example of the TDD process Introduction to unit testing in Python Python unittest Pytest Testing external dependencies Mocking Dependency injection Dependency injection in OOP Advanced pytest Grouping tests Using fixtures Summary Package Management The creation of a new package Trivial packaging in Python The Python packaging ecosystem PyPI Virtual environments Preparing an environment A note on containers Python packages Creating a package Development mode Pure Python package Cython Python package with binary code Uploading your package to PyPI Creating your own private index Summary Part IV Ongoing operations Logging Log basics Producing logs in Python Detecting problems through logs Detecting expected errors Capturing unexpected errors Log strategies Adding logs while developing Log limitations Summary Metrics Metrics versus logs Kinds of metrics Generating metrics with Prometheus Preparing the environment Configuring Django Prometheus Checking the metrics Starting a Prometheus server Querying Prometheus Proactively working with metrics Alerting Summary Profiling Profiling basics Types of profilers Profiling code for time Using the built-in cProfile module Line profiler Partial profiling Example web server returning prime numbers Profiling the whole process Generating a profile file per request Memory profiling Using memory_profiler Memory optimization Summary Debugging Detecting and processing defects Investigation in production Understanding the problem in production Logging a request ID Analyzing data Increasing logging Local debugging Python introspection tools Debugging with logs Debugging with breakpoints Summary Ongoing Architecture Adjusting the architecture Scheduled downtime Maintenance window Incidents Postmortem analysis Premortem analysis Load testing Versioning Backward compatibility Incremental changes Deploying without interruption Feature flags Teamwork aspects of changes Summary Other Books You May Enjoy Index
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/PacktPublishing
2. In the Find a repository… box, search the book title: Python Architecture Patterns: Master API design, event-driven structures, and package management in Python
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.