Test your knowledge of modern Python, libraries, async programming, and package management
uv is a Rust-based Python package manager that's 10-100x faster than pip. It's becoming increasingly popular in 2025 for AI projects.
aiohttp is the most popular library for async HTTP requests. While httpx also supports async, aiohttp is more widely used in production AI applications.
async def is used to define an asynchronous function (coroutine). You use await to call async functions.
asyncio.run(main()) is the entry point for running async code. It creates an event loop, runs the coroutine, and closes the loop.
python-dotenv loads environment variables from a .env file into os.environ. This is essential for managing API keys securely.
python -m venv .venv creates a virtual environment. The -m flag runs the venv module.
requests library is the most popular choice for synchronous HTTP requests. It's simple and widely used.
Field(alias='capitalInfo') maps capitalInfo from the API to capital_info in Python, following Python naming conventions.
asyncio.gather() runs multiple coroutines concurrently and returns their results. It's essential for parallel API calls.
type keyword for creating type aliases: type Vector = list[float]
json.loads() parses a JSON string, and response.json() is a convenience method in requests.
.env file (not tracked by git) and load it with python-dotenv. Never hardcode API keys!
async with aiohttp.ClientSession() as session: ensures the session is properly closed, even if errors occur.
.py extension.
aiohttp.ClientError is the base exception for all aiohttp client errors. You can also catch more specific errors like ClientConnectionError.