Title Page Copyright and Credits Hands-On Reactive Programming with Python Dedication Packt Upsell Why subscribe? Packt.com Contributors About the author About the reviewer Packt is searching for authors like you Preface Who this book is for What this book covers To get the most out of this book Download the example code files Conventions used Get in touch Reviews An Introduction to Reactive Programming What is reactive programming? Event-driven programming Reactive versus proactive Reactor and proactor Reactive systems Introduction to ReactiveX and RxPY ReactiveX principles Operators Installating RxPY A reactive echo application Marble diagrams The map operator The from_ operator Flow diagrams Reactivity diagrams Reactivity diagram elements Reactivity diagrams of an echo example Summary Questions Further reading Asynchronous Programming in Python What is asynchronous programming? The history of asynchronous programming in Python Asynchronous handlers with callbacks Asynchronous handlers with generators Understanding generators Using generators for asynchronous handlers Introduction to AsyncIO Futures Coroutines Event loop An HTTP echo server aiohttp An AsyncIO HTTP server Summary Questions Further reading Functional Programming with ReactiveX What is functional programming? Some base elements of functional programming Lambdas Closures Side effects and pure functions Higher-order functions Functional reactive programming Observable cycles The observable cycle issue ReactiveX Subject Solving the cycle issue with Subject Structuring functional and reactive code The HTTP echo server with an HTTP driver ReactiveX operators The empty operator The merge operator Implementation of the HTTP server driver Bootstrapping the event loop Adding the program logic Summary Questions Further reading Exploring Observables and Observers Creating observables Creating observables from values The of operator The just operator The range operator The repeat operator The never and throw operators Observables driven by time The timer operator The interval operator Custom observables The from_callback operator The create operator Hot and cold observables Operators – publish and connect Operators – ref_count and share Subscription and disposal Subscribing to an observable Disposing a subscription Custom disposal Error handling The catch_exception operator The retry operator Observables and AsyncIO The start operator The from_future operator Summary Questions Concurrency and Parallelism in RxPY Concurrency and schedulers Available schedulers The NewThread scheduler The ThreadPool scheduler The AsyncIO scheduler Summary Questions Implementation of an Audio Transcoding Server Technical requirements Structuring the project The base structure Maximizing code readability Using named tuples Using dataclasses Avoiding backslashes Introduction to Cyclotron The command-line echo example Operators used in this application The skip operator The filter operator The flat_map operator The let operator Implementation of the encoding server Parsing the configuration file Implementation of the encoder driver Using the encoder driver Exposing the REST APIs Putting it all together Using the encoding server Summary Questions Further reading Using Third-Party Services Technical requirements An introduction to S3 storage Installing Docker and Minio An introduction to Docker Docker installation on Linux Getting started with Docker Using Minio as S3 storage Using S3 as storage Implementation of the S3 driver Returning data in the encoding driver Using the S3 driver Dealing with blocking API and CPU-bound operations Using thread pools for CPU-bound operations Moving the blocking I/O to a dedicated thread Summary Questions Further reading Dynamic Reconfiguration and Error Management Monitoring file changes Understanding inotify Monitoring file changes with inotify Operators used for dynamic configuration The debounce operator The take operator The distinct_until_changed operator The start_with operator The combine_latest operator Encode driver reconfiguration Configuring the audio encoding Monitoring the configuration file Implementing an inotify driver Monitoring changes in the configuration file Error management Summary Questions Operators in RxPY Transforming observables The buffer operator The window operator The group_by operator Filtering observables The first operator The last operator The skip_last operator The take_last operator The ignore_elements operator The sample operator The distinct operator The element_at operator Combining observables The join operator The switch_latest operator The zip operator The zip_list operator Utility operators The delay operator The do_action operator The materialize/dematerialize operators The time_interval operator The timeout operator The timestamp operator The using operator The to_list operator Conditional operators The all operator The amb operator The contains operator The default_if_empty operator The sequence_equal operator The skip_until operator The skip_while operator The take_until operator The take_while operator Mathematical operators The average operator The concat operator The count operator The max operator The min operator The reduce operator The sum operator Summary Questions Further reading Testing and Debugging Testing Introduction to Python unit testing Dependency injection versus mock Testing a custom operator Injecting asynchronous obervables Testing AsyncIO code Logging Debugging Adding traces Debugging AsyncIO Summary Questions Further reading Deploying and Scaling Your Application Technical requirements Introduction to Traefik Reverse proxies and load balancers What is a reverse proxy? What is a load balancer? Traefik principles Packaging a service with Docker Compose Introduction to Docker Compose Installing Docker Compose Starting Traefik Packaging the audio transcoder How images are composed together Composing all services Using containers for horizontal scaling Adding TLS support with Let's Encrypt Introduction to Let's Encrypt Deploying on a public server Enabling the ACME protocol Summary Questions Further reading Reactive Streams for Remote Communication Communication patterns and observables Publish/subscribe Channel Request/response Observable multiplexing Framing An implementation of line-based framing Serialization An implementation of JSON serialization Routing Implementing publish/subscribe The publisher Implementation of a TCP server Implementation of the publisher The subscriber Implementation of a TCP client Implementation of the subscriber Summary Questions Further reading A Checklist of Best Practices The observable creation decision tree Keeping side-effects as small as possible What to do when nothing happens Miscellaneous recommendations Favor composition of existing operators Always specify a scheduler Subscriptions should not throw exceptions Disposal should not throw exceptions Be clear on hot and cold observables Summary Questions Further reading Assessments Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Other Books You May Enjoy Leave a review - let other readers know what you think