This is also the basis for the postgresql-wheel package, a Python wheel that contains an entire local PostgreSQL binary installation:
https://github.com/michelp/postgresql-wheel
Out of sheer laziness I used CFFI to encapsulate the build, even though there is no dynamic linking involved. There's probably a simpler way but this approach has worked very well for disposable database tests.