The Medium-Energy Gamma-ray Astronomy library MEGAlib is an open-source object-oriented software library designed to simulate and analyze data of low-to-medium-energy gamma-ray telescopes, especially Compton telescopes. The library comprises all necessary simulation and data analysis tools including geometry construction, Monte-Carlo simulation, response creation, event reconstruction, image reconstruction, and other high-level data-analysis tools.