Notes on the Creation of a Python Wrapper for the Gallica API
I recently wrote my first Python wrapper, PyGallica, to help users programatically interact with the materials in Gallica’s online library. The wrapper interfaces with Gallica’s Document API, IIIF API, and Search API, and is available for free download on my GitHub account, where it can also be copied and modified under the terms of the GNU General Public License, a copyleft license with minimal restrictions. Writing the wrapper was both a learning experience and a project that resulted in a useful tool, and I hope that writing a bit about my experience here will be a helpful window into how working on the wrapper served as both an educational process and a project with a tangible deliverable.
PyGallica makes calls to Gallica’s REST API, and constructs URLS for the user so that they can easily access information from the API within Python. The wrapper is a simple, Pythonic interface to Gallica, with the actual Gallica API doing all of the retrieval of information under the hood. All of the APIs’ original methods are available, but you call them using Python function calls and wrappings rather than typing them in your browser.
The APIs that my wrapper interfaces with allow users to conduct a variety of search types within Gallica’s holdings, and to retrieve metadata and images from the collection easily within Python. This diversity of functionality, along with the lack of an existing wrapper and Gallica’s relevance to my position as subject liaison for European Studies, were what led me to choose Gallica’s APIs for my first attempt at writing a wrapper in Python.
My experience writing PyGallica was very positive. I treated the project both as a professional development opportunity--a way to improve my existing Python skills and learn more about how API wrappers work--and a digital scholarship project with a clear deliverable that would hopefully be beneficial to others working in libraries and academia. I took a few other projects as examples, notably the HathiTrust API wrapper and the DPLA Python wrappers, which are both available on GitHub. I also looked at a number of other wrappers interfacing with non-scholarly websites, such as Flickr, to see how others had structured their code. After reviewing existing code, Googling and consulting Stack Overflow, and a healthy amount of trial and error, I was able to get a working model for one of the APIs, which was then easy to expand to assist with the other APIs that Gallica provides.
The code for my project will continue to live on my GitHub account, and was linked on the Gallica website after I shared it with Gallica staff via email. I look forward to the project continuing to live online as a freely editable and downloadable tool, and hope it is useful both as a wrapper and as example code for anyone else hoping to work on a similar project.
European Studies Librarian
University of Texas Libraries
The University of Texas at Austin