Libraries#
Python ships “batteries included”. The standard library covers most everyday needs; PyPI hosts everything else. This chapter is reference for the stdlib modules and third-party packages worth reaching for, organized by job.
For installing and managing dependencies, see Setup and Tooling. For frameworks (Django, Flask, FastAPI, orchestration, security toolkits), see Frameworks. For networking-specific libraries (sockets, HTTP, DNS, SSH, scapy), see Networking.
Standard library#
Filesystem and process#
Module |
Job |
|---|---|
|
Process environment, |
|
The operator’s path API. |
|
High-level file ops, |
|
Run external commands. |
|
|
|
Shell-style globbing. |
Data formats#
Module |
Job |
|---|---|
|
JSON encode / decode. |
|
Read / write CSV with |
|
Read INI files. |
|
Read TOML ( |
|
Parse XML. For untrusted XML use |
|
Pull-style HTML parser. For real work use
|
|
Encoding primitives. |
|
Fixed-layout binary records. |
Text and dates#
Module |
Job |
|---|---|
|
Regular expressions. |
|
String constants, |
|
Wrap and dedent. |
|
Normalization, category lookup. |
|
|
|
Dates, times, deltas, timezone-aware via |
|
IANA timezones (stdlib successor to |
|
Low-level monotonic / perf counters, sleep. |
Collections and algorithms#
Module |
Job |
|---|---|
|
|
|
Lazy combinators, |
|
|
|
Binary min-heap on a list. |
|
Binary search and ordered-list insertion. |
|
|
|
|
|
|
Concurrency and async#
Module |
Job |
|---|---|
|
Threads. GIL-bound; use for I/O-bound concurrency only. |
|
Processes. Use for CPU-bound work. |
|
High-level |
|
Async event loop, coroutines, tasks, queues, locks. |
|
Thread-safe |
Networking (stdlib)#
The deeper detail lives in Networking.
Module |
Job |
|---|---|
|
TCP / UDP / Unix sockets. The operator’s primitive. |
|
TLS wrap for sockets. |
|
HTTP and URL handling (use |
|
Low-level HTTP, ad-hoc dev server. |
|
Parse and manipulate IPv4 / IPv6 addresses and networks. |
Crypto and hashing#
Module |
Job |
|---|---|
|
Cryptographic hashes (SHA-2, SHA-3, BLAKE2). Streaming updates. |
|
Keyed-hash MAC; |
|
Cryptographically strong random for tokens, passwords,
URL-safe IDs. Replaces naive |
|
TLS contexts, certificate verification. |
|
UUID v1, v3, v4, v5. |
Persistence#
Module |
Job |
|---|---|
|
Embedded SQL. Zero-config. The operator’s local store. |
|
|
|
Object serialisation. Never unpickle untrusted data. |
|
Shallow and deep copies. |
Observability and tools#
Module |
Job |
|---|---|
|
Standard logger. Operator preference, configure once and
use |
|
Command-line parsing. |
|
Issue deprecation / runtime warnings. |
|
Format / print tracebacks programmatically. |
|
Bytecode disassembler (operator’s introspection tool). |
|
Introspect functions, classes, signatures. |
|
Type hints ( |
|
Plain-record class generator. |
Third-party core#
The packages every operator project tends to use. Only the stable, actively maintained, broadly adopted ones; deprecated and superseded packages are dropped from the catalog.
HTTP and networking#
Library |
Purpose |
|---|---|
sync + async HTTP. Modern default for new code. |
|
sync HTTP. The classic; still rock-solid for one-off scripts. |
|
async HTTP client + server. |
|
RFC 6455 client and server. |
CLI and UX#
Library |
Purpose |
|---|---|
CLI from type hints. The default for new CLIs. |
|
Declarative CLI. What |
|
Colour, tables, progress bars, tracebacks for terminal output. |
|
Interactive shells with completion, history, mouse. |
Data#
Library |
Purpose |
|---|---|
Runtime validation from type hints. The default for parsing JSON into models. |
|
Dataclasses with more flexibility (validators, slots, converters). |
|
Fast columnar dataframe. The default for
single-host data work over |
|
ORM and query builder. The default RDBMS abstraction. |
|
Schema migrations for |
Logging and observability#
Library |
Purpose |
|---|---|
Structured logging. Default for new services. |
|
Zero-config logging for scripts. |
|
Error reporting + performance traces to Sentry. |
|
Vendor-neutral traces and metrics. |
Resilience#
Library |
Purpose |
|---|---|
Retry decorators with backoff. The modern default. |
Testing#
Library |
Purpose |
|---|---|
The test framework. Fixtures, parametrize, plugins. |
|
Property-based testing. |
|
Line and branch coverage. |
OSINT libraries#
API clients and enumeration tools for open-source intelligence.
API clients#
Library |
Purpose |
|---|---|
Python client for Shodan internet-wide search. |
|
Python client for Censys. |
|
DNS queries (also covered in Networking). |
|
Twitter / X API client. |
|
Reddit API client. |
Enumeration#
Library |
Purpose |
|---|---|
Domain WHOIS lookups. |
|
Username search across hundreds of sites; CLI and library. |
|
Parse, validate, geocode phone numbers. |
|
Geocoding clients for Nominatim, Google, Mapbox. |
Scraping primitives#
Library |
Purpose |
|---|---|
Permissive HTML parser. The default for messy real-world pages. |
|
Fast XML / HTML parser. |
|
Article-body extraction from arbitrary web pages.
Modern, maintained successor to |
|
RSS / Atom feed parsing. |
Cryptography#
Library |
Purpose |
|---|---|
The modern Python crypto library. |
|
Drop-in for the abandoned |
|
Password hashing with multiple backends (bcrypt, scrypt, argon2). |
|
Argon2 password hashing (the default for new deployments). |
Don’t roll your own crypto. Use library primitives, never raw
hashlib for password storage.
Security linting#
The operator’s audit toolkit for both source code and installed packages.
Tool |
Catches |
|---|---|
Python-specific security smells ( |
|
semgrep |
Same surface plus framework-aware rules (Django, Flask, FastAPI). |
Vulnerable installed packages (CVE feed). |
|
Same, lockfile-aware; container-aware. |
|
|
Bandit rules ported to |
References#
Networking for the network-specific libraries (sockets, HTTP, DNS, SSH, scapy).
Frameworks for the framework-class libraries (Django, FastAPI, pandas, Celery, MCP).
The Python Standard Library, the reference documentation.
PyPI, the package index.
Awesome Python, a curated list of Python libraries by topic.