Alloy cluster expansions (CEs) provide an accurate and computationally efficient mapping of the potential energy surface of multi-component systems that enables comprehensive sampling of the many-dimensional configuration space. Here, we introduce icet, a flexible, extensible, and computationally efficient software package for the construction and sampling of CEs. icet is largely written in Python for easy integration in comprehensive workflows, including first-principles calculations for the generation of reference data and machine learning libraries for training and validation. The package enables training using a variety of linear regression algorithms with and without regularization, Bayesian regression, feature selection, and cross-validation. It also provides complementary functionality for structure enumeration and mapping as well as data management and analysis. Potential applications are illustrated by two examples, including the computation of the phase diagram of a prototypical metallic alloy and the analysis of chemical ordering in an inorganic semiconductor.