Please see the new location of our Python guide for Connect at docs.posit.co: https://docs.posit.co/connect/admin/python/
Use Cases for Python with Posit Connect
You can publish content to Posit Connect that uses Python. This could include for interactive data exploration and data loading (pandas
), visualization (matplotlib
, seaborn
), natural language processing (spacy
, gensim
), and machine learning (pytorch
, scikit-learn
, statsmodels
).
Common use cases with Python and Posit Connect include:
- Push-button publishing of Jupyter Notebooks to Posit Connect
- Building interactive Shiny applications and dashboards on top of existing Python code and libraries
- Using mixed Python and R content in R Markdown documents and reports
- Scheduling Python-based data processing / ETL scripts or model training jobs
- Using Python libraries with R Markdown notebooks for interactive and exploratory analyses
- Publishing Flask applications and APIs
- Deploying Plumber APIs that execute Python scripts or use Python libraries when an API is queried
Configuring Python with Posit Connect
What are the requirements for using Python with Posit Connect?
Posit Connect (version 1.7.0 and higher) can be configured to point to one or more versions of Python on the server that will be used when Python content is published. Python support and the locations of the Python environments are specified in the Posit Connect configuration file.
For more details, refer to the Python section in the Posit Connect documentation.
The client machine that is publishing Python content should be using reticulate
version 0.8.13 or newer.
Which versions of Python are compatible with Posit Connect?
The reticulate
package description shows compatible versions of Python. Integration with NumPy is optional and requires NumPy >= 1.6.
For compatible versions of Python in Posit Connect, see the admin guides.
Can I use multiple versions of Python with Posit Connect?
Yes, Posit Connect supports and recommends multiple installed versions of Python on the server. See the Upgrading Python section in the Posit Connect documentation..
Publishing Python Content to Posit Connect
How do I include Python code or scripts within an R application?
The reticulate package provides a comprehensive set of tools for interoperability between Python and R. Posit Connect supports the use of reticulate
and will recreate both the R and Python packages in the environment on the Posit Connect server when a project is deployed.
Where can I find examples of using Python with Posit Connect?
Examples of Python and R content with Connect can be found on this demo content repo and in the python-examples repository on GitHub.
How can I configure reticulate to point to a specific Python environment?
The reticulate package can now self-discover the python version. For more details, refer to the Python Version Configuration section in the reticulate
documentation.
The historical approach for configuring reticulate
for use with the RStudio IDE and publishing Python content to Posit Connect was to set the RETICULATE_PYTHON
environment variable to point to the desired Python executable.
This approach was supported starting in reticulate
0.8.13.
For example, you could set the following in your .Renviron:
RETICULATE_PYTHON=/usr/local/bin/python3
This allowed you to remove any hard-coded references to Python environments from your application code and avoids the need to switch use_python
or other configurations in reticulate
between developing projects in Posit Workbench and publishing projects to Posit Connect.
How does Posit Connect determine the Python packages that are used in my project?
Please see the Publishing part of the Posit Connect User guide and the Package Management section of the Posit Connect Admin guide for detailed information.
The reticulate::py_config() function can be used to verify which Python executable and library paths are being used by the rsconnect
package in the RStudio IDE to generate the list of Python packages.
Can I publish standalone Python applications such as Flask APIs to Posit Connect?
Yes. Flask applications and many other content types built with Python can be published to Posit Connect Connect. The package requires an API key associated with an operational installation of Posit Connect is available. Detailed information is available in the Posit Connect Flask User Guide
For more detail on what content is available and how to deploy, please see our Posit Connect User Guide.
Publishing Jupyter Notebooks to Posit Connect
How do I publish Jupyter Notebooks to Posit Connect?
Please see the Posit Connect User guide section on Publishing from the Command line for details.
Which languages / kernels can I use when publishing Jupyter Notebooks?
Please see the Posit Connect User Guide for deploying Jupyter Notebooks
For more details, refer to the rsconnect-python documentation.
Can I schedule and email published Jupyter Notebooks?
Yes. See the Scheduling section of the Posit Connect User Guide.
Troubleshooting Python with Posit Connect
If you encounter errors when installing Python on the Posit Connect server or publishing apps with Python content, refer to the support article on Troubleshooting Python with RStudio Connect.
Comments
0 comments
Article is closed for comments.