On Embedding Gretl in a Python Module Christine Choirat and Raffaello Seri 1 Department of Quantitative Methods, School of Economics and Business Management, Universidad de Navarra, Pamplona (Spain) cchoirat@unav.es 2 Dipartimento di Economia, Università degli Studi dell’Insubria , Varese (Italy) raffaello.seri@uninsubria.it Abstract. Additional functionalities can be developed for Gretl either directly in the main C code or with the Gretl scripting language. We illustrate through an example how it would be possible to wrap the C source of Gretl with SWIG to create an interface to Python that makes use of the matrix library NumPy. Such an interface would make it easier for users to extend Gretl since it would allow for developing and distributing Gretl extensions as Python modules. Key words: Python, C, SWIG, Libgretl API 1 Introduction and motivation To extend the functionalities of Gretl, 3 it is either possible to add them in the C source or to use the Gretl scripting language. The former option is only possible for users who have a very sound knowledge of C and who understand how the source of Gretl is structured. Besides, it makes it hard to share these added functionalities with the rest of the user base unless they are accepted for a next release. The latter option requires learning yet another field-specific language. Even if the speed benchmarks are good and the syntax easy, a program-specific macro language can never be as powerful as a full-featured scripting language (either domain-specific such as R, see [1, 2], or general such as Python, see [3]). The scripting language that we have chosen to embed Gretl in is Python, which is free, open-source and available on many platforms. Python is indeed a very powerful, easy-to-learn and well-documented language with a very clear syntax. Writing and distributing documented Python modules is simple as well. Matrices are not a native Python data type. However, the very mature project NumPy 4 provides an efficient implementation of N −dimensional arrays (and 3 See http://gretl.sourceforge.net/. 4 See http://www.scipy.org/.