  The collection of gravitational waves (GWs) that are either too weak or too
numerous to be individually resolved is commonly referred to as the
gravitational-wave background (GWB). A confident detection and model-driven
characterization of such a signal will provide invaluable information about the
evolution of the Universe and the population of GW sources within it. We
present a new, user-friendly Python--based package for gravitational-wave data
analysis to search for an isotropic GWB in ground--based interferometer data.
We employ cross-correlation spectra of GW detector pairs to construct an
optimal estimator of the Gaussian and isotropic GWB, and Bayesian parameter
estimation to constrain GWB models. The modularity and clarity of the code
allow for both a shallow learning curve and flexibility in adjusting the
analysis to one's own needs. We describe the individual modules which make up
{\tt pygwb}, following the traditional steps of stochastic analyses carried out
within the LIGO, Virgo, and KAGRA Collaboration. We then describe the built-in
pipeline which combines the different modules and validate it with both mock
data and real GW data from the O3 Advanced LIGO and Virgo observing run. We
successfully recover all mock data injections and reproduce published results.
