  We present a new public Python package, DarkHistory, for computing the
effects of dark matter annihilation and decay on the temperature and ionization
history of the early universe. DarkHistory simultaneously solves for the
evolution of the free electron fraction and gas temperature, and for the
cooling of annihilation/decay products and the secondary particles produced in
the process. Consequently, we can self-consistently include the effects of both
astrophysical and exotic sources of heating and ionization, and automatically
take into account backreaction, where modifications to the
ionization/temperature history in turn modify the energy-loss processes for
injected particles. We present a number of worked examples, demonstrating how
to use the code in a range of different configurations, in particular for
arbitrary dark matter masses and annihilation/decay final states. Possible
applications of DarkHistory include mapping out the effects of dark matter
annihilation/decay on the global 21cm signal and the epoch of reionization, as
well as the effects of exotic energy injections other than dark matter
annihilation/decay. The code is available at
https://github.com/hongwanliu/DarkHistory with documentation at
https://darkhistory.readthedocs.io . Data files required to run the code can be
downloaded at https://doi.org/10.7910/DVN/DUOUWA .
