Building Customized Async Web Protocol from AsyncIO|姜韋辰 (daniel)|PyCon APAC 2022
PyCon Taiwan
PyCon APAC 2022|一般演講 Talks|國泰金控 Cathay Financial Holdings / 美光科技 Micron 冠名贊助
✏️ 共筆 Note:https://hackmd.io/@pycontw/B17AUTXks 🖐🏻 Slido:https://app.sli.do/event/aH6RxX7bYGg8WR3GvM3Q3X 🪧 投影片 Slides:https://docs.google.com/presentation/d/1OEAJF6cP_m62QMiprRzWEg6jOclR-kHdLl8g9hk9iZw/edit?usp=sharing 💬 語言 Language:中文演講/英文投影片 Chinese talk w. English slides 🎯 層級 Level:進階 Experienced 🔎 分類 Category:Python 核心 Python Core
💡 摘要 Abstract 💡 Despite their powerful features and flexibility, the low-level APIs for library and framework developers provided in Asyncio are underutilized. One reason might be the high entry barrier – prerequisites like understanding protocols knowledge and asynchronous design patterns. I am sharing my humble experience with Asyncio here. I show you how to implement a network protocol, specifically Websocket, with Protocol and Transport, two of the staple low-level APIs in the package. You will learn how to establish a consensual connection and communicate between the server and the client. While the main focus is on low-level APIs (e.g., we will use Transport to send messages to another endpoint) , we will be using some high-level APIs (e.g., StreamReader, Queue) for auxiliary purposes like message handling. It is hoped that the techniques and familiarity gained with asyncio serve as the basis for your customized network protocol and libraries, even for commercial purposes, in the future.
🪄 說明 Description 🪄 Asynchronous web services and frameworks have become ubiquitous in recent years due to their efficiency. In Python development, these very commonly translate to using packages like aiohttp, for sending async network requests, or Uvicorn for setting up web servers for other backend services like FastApi, just to name a few. Though these packages cover most common scenarios and are production ready, their one-size-fits-all approach may fail Python web developers with more flexible and specialized use in mind. As such, for more customizability and specialized feature development, we delve into lower-level APIs like Protocol, Transport provided in Asyncio, which serves as the basis on which the aforementioned packages were built. Doing so, for example, allows us to develop a self-defined inter-process communication (IPC) library or create network protocol.
In this sharing, I will implement application-layer protocol, specifically, WebSocket, as the motivating example, using the low-level API Transport and Protocol from the package asyncio to handle the connection and communication between the server and the client, which is the main focus of the proposed presentation. However, due to the constraint of time, I will still use high-level APIs to expedite the building of part of data reception from the client. This presentation will familiarize you with
- Asyncio low-level API like Protocol and Transport: you will be able to build your async framework, Inter-process communication, Network Protocols etc.
- The patterns of async development
🚀 講者介紹 About Speaker - 姜韋辰 (daniel) 🚀 我是一名後端工程師,熟悉常用的 Python web 框架,喜歡挑戰各種業務場景的服務。專注於系統開發以及服務優化,因應業務需求,偶而也會下海寫寫前端,最近比較著迷 infra 相關建置及維護。
#pycontw #pyconapac2022 #pycontw #asyncio
Follow “PyCon Taiwan” ⭐️ Official Website: https://tw.pycon.org ⭐️ Facebook: https://www.facebook.com/pycontw ⭐️ Instagram: https://www.instagram.com/pycontw ⭐️ Twitter: https://twitter.com/PyConTW ⭐️ LinkedIn: https://www.linkedin.com/company/pycontw ⭐️ Blogger: https://pycontw.blogspot.com ... https://www.youtube.com/watch?v=fssvxxq7mLk
150913439 Bytes