pystata - Call Stata from Python¶
The pystata Python package allows you to call Stata from within Python. It includes two sets of tools for interacting with Stata from within Python:
Three IPython magic commands
A suite of API functions
The magic commands can be used to access Stata and Mata conveniently in an IPython (interactive Python) kernel-based environment, such as Jupyter Notebook and console, Jupyter Lab and console, and within other environments that support the IPython kernel, such as Spyder IDE and PyCharm IDE.
The API functions can be used to interact with Stata and Mata from within both IPython and non-IPython environments. For example, they can be used when accessing Python from a Jupyter Notebook or from a command line, such as Python’s IDLE, the Windows Command Prompt, a macOS terminal, or a Unix terminal.
The magic commands and API functions both can be used together with the Stata Function Interface (sfi) module, making it easier to interact between Stata and Python.
Note that the pystata Python package is to call Stata from within the Python environment. If you are instead interested in calling Python from within Stata, you can refer to the [P] python entry in the Programming Reference Manual for the full documentation.