  By measuring, modeling and interpreting cosmological datasets, one can place
strong constraints on models of the Universe. Central to this effort are
summary statistics such as power spectra and bispectra, which condense the
high-dimensional dataset into low-dimensional representations. In this work, we
introduce a modern set of estimators for computing such statistics from
three-dimensional clustering data, and provide a flexible Python
implementation; PolyBin3D. Working in a maximum-likelihood formalism, we derive
general estimators for the two- and three-point functions, which yield unbiased
spectra regardless of the survey mask, weighting scheme, and presence of holes
in the window function. These can be directly compared to theory without the
need for mask-convolution. Furthermore, we present a numerical scheme for
computing the optimal (minimum-variance) estimators for a given survey, which
is shown to reduce error-bars on large-scales. Our Python package includes both
general "unwindowed'' estimators and idealized equivalents (appropriate for
simulations), each of which are efficiently implemented using fast Fourier
transforms and Monte Carlo summation tricks, and additionally supports GPU
acceleration. These are extensively validated in this work, with Monte Carlo
convergence (relevant for masked data) achieved using only a small number of
iterations (typically $<10$ for bispectra). This will allow for fast and
unified measurement of two- and three-point functions from current and upcoming
survey data.
