HL7 version 2 is the most popular messaging standard for clinical systems interoperability. Most of the tools for messaging management are Java or .NET based, while Python programming language lacks of comparable solutions. This paper describes HL7apy, an open-source HL7 v2 compliant messaging library, written in Python. The library offers means to create, parse, navigate and validate messages. As an example application, we present a full implementation of the IHE Patient Demographics Query ITI-21 transaction. The resulting module has been integrated in GNU Health, a popular open-source Hospital Information System.