gitmyhub

aiohttp

Python ★ 17k updated 1d ago

Asynchronous HTTP client/server framework for asyncio and Python

Async HTTP client and server for Python built on asyncio. Make many concurrent requests, or build a web API with routing, middleware, and WebSockets.

Pythonasynciosetup: easycomplexity 3/5

Aiohttp is a Python library for making HTTP requests and building HTTP servers, built around Python's asyncio system. Asyncio is Python's built-in approach to running many tasks concurrently without using threads — instead of waiting for one network request to finish before starting the next, your program can handle many requests at the same time in a single thread.

The library works in two directions. As a client, it lets you fetch web pages or call APIs asynchronously — the README's example shows fetching a URL and reading the status code and response body with just a few lines of code. As a server, it lets you define URL routes and handler functions to build a web API or web application, with built-in support for middleware (code that runs before or after every request) and pluggable routing.

Aiohttp also has built-in support for WebSockets on both client and server sides. WebSockets are a protocol that keeps a persistent two-way connection open between client and server, useful for things like live chat or real-time data feeds. The server example in the README demonstrates an echo WebSocket that sends back whatever the client sends.

You would reach for aiohttp when building a Python application that needs to make many concurrent network requests (like a web scraper or API aggregator), or when building a server that needs to handle many simultaneous connections efficiently. It is licensed under Apache 2.0.

Where it fits