Python Web Development with Sanic: An in-depth guide for Python web developers to improve the speed and scalability of web apps
Book information
Description
Build a performant and scalable web application using Sanic, along with maintaining clean code to fit your unique challenges and business requirements Key Features Expand your knowledge of web application architecture for building scalable web apps Learn the core philosophies of performance and scalability from one of the creators of Sanic Create a complete Python web app from scratch and learn to translate the knowledge you gain across various use cases Cover Title Page Copyright and Credits Contributors Table of Contents Preface Part 1:Getting Started with Sanic Chapter 1: Introduction to Sanic and Async Frameworks Technical requirements What is Sanic? Leveling up Framework versus server Web server Web framework Why we use Sanic—build fast, run fast Simple and lightweight Unopinionated and flexible Performant and scalable Production-ready Trusted by millions Community-driven What drives code decisions? Summary Chapter 2: Organizing a Project Technical requirements Setting up an environment and directory Environment Sanic CLI Directory structure Using blueprints effectively Blueprint registration Blueprint versioning Grouping blueprints Wiring it all up Controlled imports Factory pattern Autodiscovery Running our application Summary Part 2:Hands-On Sanic Chapter 3: Routing and Intaking HTTP Requests Technical requirements Understanding HTTP methods Using HTTP methods on route handlers Advanced method routing Method safety and request body RESTful API design Simplifying your endpoints with CBVs Blanket support for OPTIONS and HEAD Paths, slashes, and why they matter Strict slashes Extracting information from the path Advanced path parameters Custom parameter matching Modifying matched parameter values API versioning Should all of my routes bump versions? Version prefixing Virtual hosts Serving static content Serving static content from Sanic Serving static content with Nginx Streaming static content Summary Chapter 4: Ingesting HTTP Data Technical requirements Reading cookies and headers Headers are flexible Authentication headers Context headers Sanic extracts header data for us Headers as multi-dict Getting information from cookies (yum!) Reading forms, query arguments, files, JSON, and more Query arguments Forms and files Consuming JSON data Getting streaming data Validating data Step 1—getting started and making a decorator Step 2—reading the handler signature Step 3—modeling Step 4—model hydration Step 5—performing validations Taking it to the next level with third-party packages Summary Chapter 5: Building Response Handlers Technical requirements Examining the HTTP response structure The HTTP response status Response groupings A response through exceptions Custom status Headers The response body Rendering HTML content Delivering HTML files Basic templating Using a templating engine Serializing JSON content Choosing a serializer Serializing custom objects Best practices Streaming data File streaming Server-sent events for push communication Starting with the basics Building some SSE objects Websockets for two-way communication Setting response headers and cookies Responding with a request ID Setting response cookies Summary Chapter 6: Operating Outside the Response Handler Technical requirements Making use of ctx Altering requests and responses with middleware Request middleware Response middleware Responding early (or late) with middleware Middleware and streaming responses Leveraging signals for intra-worker communication Signal definitions Using built-in signals Custom signals Waiting on events Mastering HTTP connections Keep-Alive within Sanic Caching data per connection Handling exceptions like a pro Implementing proper exception handling Bad exception messages Misusing statuses Responses through raising an exception Fallback handling Catching exceptions Background task processing Adding tasks to the loop Integrating with an outside service Designing an in-process task queue Summary Chapter 7: Dealing with Security Concerns Technical requirements Setting up an effective CORS policy What is the security issue with ineffective CORS? Protecting applications from CSRF Solutions that do not work Solutions that do work Samesite cookies Protecting your Sanic app with authentication Using API keys Understanding session-based versus non-session-based authentication Using sessions JSON Web Tokens (JWTs) Summary Chapter 8: Running a Sanic Server Technical requirements Handling the server life cycle Server listeners Configuring an application What is the Sanic configuration object? How can an application's configuration object be accessed? How can the configuration object be set? Some general rules about configuration Running Sanic locally How does running Sanic locally differ from production? Deploying to production Choosing the right server option How to choose a deployment strategy? Securing your application with TLS Setting up TLS in Sanic Getting and renewing a certificate from Let's Encrypt Deployment examples PaaS Kubernetes (as-a-service) Summary Part 3:Putting It All together Chapter 9: Best Practices to Improve Your Web Applications Technical requirements Implementing practical real-world exception handlers Catching errors with middleware Catching errors with signals Catching the error and responding manually Modifying ErrorHandler Setting up a testable application Getting started with sanic-testing A more practical test client implementation Using ReusableClient for testing Gaining insight from logging and tracing Types of Sanic loggers Creating your own loggers, my first step in application development Configuring logging Adding color context Adding some basic tracing with request IDs Using X-Request-ID Managing database connections To ORM or not to ORM, that is the question Creating a custom data access layer in Sanic Connecting Sanic to Redis Summary Chapter 10: Implementing Common Use Cases with Sanic Technical requirements Synchronizing and scaling websocket feeds Powering a progressive web application Dealing with subdomains and CORS Running a development server Designing a GraphQL API Why would I want to use GraphQL? Adding GraphQL to Sanic Building a Discord bot: running Sanic from another service Building a simple Discord bot Running the Discord bot from Sanic Creating an HTTP to HTTPS proxy: nesting Sanic inside Sanic Summary Chapter 11: A Complete Real-World Example Technical requirements The process of building a web application Step 1—Define the functionality and workflow Step 2—Decide on the technology stack Step 3—Architect the data structures Step 4—Plan and build the user interface Step 5—Build the application infrastructure Step 6—Prototype the minimally viable backend features Step 7—Create continuous integration, deployment, and automation tools Step 8—Iterate, iterate, iterate Highlighting select features of the Booktracker Development environment Creating a better factory pattern with setup functions The data access layer Authentication flow Summary Putting it all together Index Other Books You May Enjoy
Similar books
Python Web Development with Sanic: An in-depth guide for Python web developers to improve the speed and scalability of web applications
2022 · EPUB
MySQL® Notes for Professionals book
2018 · PDF
MrExcel 2022: Boosting Excel
2022 · PDF
MrExcel 2022: Boosting Excel
2022 · PDF
Session C11: Ancient Cultural Landscapes in South Europe – their Ecological Setting and Evolution, Session C22: Gardeners from South America, Session S04: Agro-Pastoralism and Early Metallurgy Sessions, Session WS29: The Idea of Enclosure in Recent Iberian Prehistory, Session C88: Rhytmes et causalites des dynamiques de l'anthropisation en Europe entre 6500 ET 500 BC: Hypotheses socio-culturelles et/ou climatiques: Proceedings of the XV UISPP World Congress (Lisbon 4-9 September 2006) / Actes du XV Congrès Mondial (Lisbonne 4-9 Septembre 2006) Vol.36
2010 · PDF
THE BRITISH ARMY IN INDIA: ITS PRESERVATION BY AN APPROPRIATE CLOTHING, HOUSING, LOCATING, RECREATIVE EMPLOYMENT, AND HOPEFUL ENCOURAGEMENT OF THE TROOPS. with AN APPENDIX ON INDIA : THE CLIMATE OP ITS HILLS ; THE DEVELOPMENT OF ITS RESODRCBS, INDUSTRY, AND ARTS ; THE ADMINISTRATION OF JUSTICE ; THE BLACK ACT ; THE PROGRESS OF CHRISTIANITY ; THE TRAFFIC IN OPIUM ; THE VALUE OF INDIA ; PERMANENT CAUSES OF DISAFFECTION, AND OF THE RECENT REBELLION ; THE TRADITIONARY POLICY; MISGOVERNMENT BY NATIVE RULERS ; ANNEXATIONS OF THEIR TERRITORY, ETC.
1858 · PDF
Idries Shah 27 Books Collection : A Perfumed Scorpion, A Veiled Gazelle, Caravan of Dreams, Darkest England, Destination Mecca, Evenings with Idries Shah, Knowing How to Know, Learning How to Learn, Letters and Lectures of Idries Shah, Neglected aspects of Sufi study, Observations, Oriental Magic, Reflections, Seeker after Truth, Special Illumination, Special Problems in the study of Sufi ideas, Sufi thought and action, Tales of the Dervishes, The Dermis Probe, The Elephant in the Dark, The Englishman Handbook, Idries Shah Antology, The Magic Monastery, The natives are restless, wisdom of the Idiots PDF.
2022 · PDF
The travels of Capts. Lewis and Clarke from St. Louis, by way of the Missouri and Columbia rivers, to the Pacific ocean; performed in the years 1804, 1805 & 1806, by order of the government of the United States. Containing delineations of the manners, customs, religion, &c. of the Indians, comp. from various authentic sources, and original documents, and a summary of the Statistical view of the Indian nations, from the official communication of Meriwether Lewis. Illustrated with a map of the country, inhabited by the western tribes of Indians
1809 · PDF