1- # The rsconnect-python Library
1+ # The rsconnect-python CLI and library
22
3- This package is a library used by the [ ` rsconnect-jupyter ` ] ( https://github.com/rstudio/rsconnect-jupyter )
4- package to deploy Jupyter notebooks to RStudio Connect. It contains a full deployment
5- API so can also be used by other Python-based deployment tools. Other types of content
6- supported by RStudio Connect may also be deployed by this package, including WSGi-style
7- APIs, as well as Dash, Streamlit, and Bokeh applications.
3+ This package provides both a CLI (command-line interface) and a library for interacting
4+ with and deploying to RStudio Connect. The library is also used by the
5+ [ ` rsconnect-jupyter ` ] ( https://github.com/rstudio/rsconnect-jupyter ) package to deploy
6+ Jupyter notebooks via the Jupyter web console. Many types of content supported by RStudio
7+ Connect may be deployed by this package, including WSGI-style APIs, Dash, Streamlit, and
8+ Bokeh applications.
89
9- > ** Important:** Streamlit and Bokeh support in RStudio Connect are currently in
10- > beta. You should not rely on them for deployments in production.
10+ > ** Important:** Bokeh support in RStudio Connect is currently in beta.
1111
12- A command-line deployment tool is also provided that can be used directly to deploy
13- Jupyter notebooks, Python APIs and apps. Content types not directly supported by the
14- CLI can also be deployed if they include a prepared ` manifest.json ` file. See
15- [ "Deploying R or Other Content"] ( #deploying-r-or-other-content ) for details.
12+ Content types not directly supported by the CLI may also be deployed if they include a
13+ prepared ` manifest.json ` file. See [ "Deploying R or Other
14+ Content"] ( #deploying-r-or-other-content ) for details.
1615
1716## Deploying Python Content to RStudio Connect
1817
19- In addition to various kinds of R content, RStudio Connect also supports the deployment
20- of Jupyter notebooks, Python APIs (such as ` flask ` -based) and apps (such as Dash, Streamlit,
21- and Bokeh apps). Much like deploying R content to RStudio Connect, there are some caveats to
22- understand when replicating your environment on the RStudio Connect server:
18+ RStudio Connect supports the deployment of Jupyter notebooks, Python APIs (such as
19+ ` flask ` -based) and apps (such as Dash, Streamlit, and Bokeh apps). Much like deploying R
20+ content to RStudio Connect, there are some caveats to understand when replicating your
21+ environment on the RStudio Connect server:
2322
24- RStudio Connect insists on matching <MAJOR.MINOR> versions of Python. For example,
25- a server with only Python 3.5 installed will fail to match content deployed with
26- Python 3.4 . Your administrator may also enable exact Python version matching which
23+ RStudio Connect insists on matching ` <MAJOR.MINOR> ` versions of Python. For example,
24+ a server with only Python 3.8 installed will fail to match content deployed with
25+ Python 3.7 . Your administrator may also enable exact Python version matching which
2726will be stricter and require matching major, minor, and patch versions. For more
2827information see the [ RStudio Connect Admin Guide chapter titled Python Version
2928Matching] ( https://docs.rstudio.com/connect/admin/python.html#python-version-matching ) .
3029
3130### Installation
3231
33- To install ` rsconnect-python ` from this repository:
32+ To install ` rsconnect-python ` from PYPI, you may use any python package manager such as
33+ pip:
3434
3535``` bash
36- git clone https://github.com/rstudio/rsconnect-python
37- cd rsconnect-python
38- python setup.py install
36+ pip install rsconnect-python
3937```
4038
41- To install the current version directly from pip :
39+ You may also build and install a wheel directly from a repository clone :
4240
4341``` bash
44- pip install rsconnect-python
42+ git clone https://github.com/rstudio/rsconnect-python.git
43+ cd rsconnect-python
44+ pip install pipenv
45+ make deps dist
46+ pip install ./dist/rsconnect_python-* .whl
4547```
4648
4749### Using the rsconnect CLI
@@ -50,9 +52,9 @@ Here's an example command that deploys a Jupyter notebook to RStudio Connect.
5052
5153``` bash
5254rsconnect deploy notebook \
53- --server https://my. connect.server :3939 \
54- --api-key my-api-key \
55- my-notebook.ipynb
55+ --server https://connect.example.org :3939 \
56+ --api-key my-api-key \
57+ my-notebook.ipynb
5658```
5759
5860> ** Note:** The examples here use long command line options, but there are short
@@ -94,27 +96,27 @@ compinit
9496### Managing Server Information
9597
9698The information used by the ` rsconnect ` command to communicate with an RStudio Connect
97- server can be tedious to repeat on every command. To help, the CLI supports the idea
99+ server can be tedious to repeat on every command. To help, the CLI supports the idea
98100of saving this information, making it usable by a simple nickname.
99101
100102> ** Important:** One item of information saved is the API key used to authenticate with
101- > RStudio Connect. Although the file where this information is saved is marked as
103+ > RStudio Connect. Although the file where this information is saved is marked as
102104> accessible by the owner only, it's important to remember that the key is present
103105> in the file as plain text so care must be taken to prevent any unauthorized access
104106> to the server information file.
105107
106108#### TLS Support and RStudio Connect
107109
108110Usually, an RStudio Connect server will be set up to be accessed in a secure manner,
109- using the ` https ` protocol rather than simple ` http ` . If RStudio Connect is set up
111+ using the ` https ` protocol rather than simple ` http ` . If RStudio Connect is set up
110112with a self-signed certificate, you will need to include the ` --insecure ` flag on
111- all commands. If RStudio Connect is set up to require a client-side certificate chain,
113+ all commands. If RStudio Connect is set up to require a client-side certificate chain,
112114you will need to include the ` --cacert ` option that points to your certificate
113- authority (CA) trusted certificates file. Both of these options can be saved along
115+ authority (CA) trusted certificates file. Both of these options can be saved along
114116with the URL and API Key for a server.
115117
116118> ** Note:** When certificate information is saved for the server, the specified file
117- > is read and its _ contents_ are saved under the server's nickname. If the CA file's
119+ > is read and its _ contents_ are saved under the server's nickname. If the CA file's
118120> contents are ever changed, you will need to add the server information again.
119121
120122See the [ Network Options] ( #network-options ) section for more details about these options.
@@ -125,13 +127,13 @@ Use the `add` command to store information about an RStudio Connect server:
125127
126128``` bash
127129rsconnect add \
128- --api-key my-api-key \
129- --server https://my. connect.server :3939 \
130- --name myserver
130+ --api-key my-api-key \
131+ --server https://connect.example.org :3939 \
132+ --name myserver
131133```
132134
133135> ** Note:** The ` rsconnect ` CLI will verify that the serve URL and API key
134- > are valid. If either is found not to be, no information will be saved.
136+ > are valid. If either is found not to be, no information will be saved.
135137
136138If any of the access information for the server changes, simply rerun the
137139` add ` command with the new information and it will replace the original
@@ -173,14 +175,14 @@ You can verify that a URL refers to a running instance of RStudio Connect by usi
173175the ` details ` command:
174176
175177``` bash
176- rsconnect details --server https://my. connect.server :3939
178+ rsconnect details --server https://connect.example.org :3939
177179```
178180
179181In this form, ` rsconnect ` will only tell you whether the URL given does, in fact, refer
180- to a running RStudio Connect instance. If you include a valid API key:
182+ to a running RStudio Connect instance. If you include a valid API key:
181183
182184``` bash
183- rsconnect details --server https://my. connect.server :3939 --api-key my-api-key
185+ rsconnect details --server https://connect.example.org :3939 --api-key my-api-key
184186```
185187
186188the tool will provide the version of RStudio Connect (if the server is configured to
@@ -244,7 +246,7 @@ rsconnect deploy notebook --static my-notebook.ipynb
244246### Creating a Manifest for Future Deployment
245247
246248You can create a ` manifest.json ` file for a Jupyter Notebook, then use that manifest
247- in a later deployment. Use the ` write-manifest ` command to do this.
249+ in a later deployment. Use the ` write-manifest ` command to do this.
248250
249251The ` write-manifest ` command will also create a ` requirements.txt ` file, if it does
250252not already exist or the ` --force-generate ` option is specified. It will contain the
@@ -262,8 +264,8 @@ rsconnect write-manifest notebook my-notebook.ipynb
262264
263265### API/Application Deployment Options
264266
265- There are a variety of options available to you when deploying a Python WSGi -style API,
266- Dash, Streamlit, or Bokeh application. All options below apply equally to ` api ` ,
267+ There are a variety of options available to you when deploying a Python WSGI -style API,
268+ Dash, Streamlit, or Bokeh application. All options below apply equally to ` api ` ,
267269` dash ` , ` streamlit ` , and ` bokeh ` sub-commands.
268270
269271#### Including Extra Files
@@ -278,17 +280,17 @@ rsconnect deploy api flask-api/ data.csv
278280
279281Since deploying an API or application starts at a directory level, there will be times
280282when some files under that directory subtree should not be included in the deployment
281- or manifest. Use the ` --exclude ` option to specify files to exclude. An exclusion may
283+ or manifest. Use the ` --exclude ` option to specify files to exclude. An exclusion may
282284be a glob pattern and the ` --exclude ` option may be repeated.
283285
284286``` bash
285287rsconnect deploy dash --exclude " workfiles/*" dash-app/ data.csv
286288```
287289
288290You should always quote a glob pattern so that it will be passed to ` rsconnect ` as-is
289- instead of letting the shell expand it. If a file is specifically listed as an extra
291+ instead of letting the shell expand it. If a file is specifically listed as an extra
290292file that also matches an exclusion pattern, the file will still be included in the
291- deployment (i.e., extra files trumps exclusions ).
293+ deployment (i.e., extra files take precedence ).
292294
293295#### Package Dependencies
294296
@@ -316,7 +318,7 @@ ensuring that you use the same Python that you use to run your API or applicatio
316318### Creating a Manifest for Future Deployment
317319
318320You can create a ` manifest.json ` file for an API or application, then use that
319- manifest in a later deployment. Use the ` write-manifest ` command to do this.
321+ manifest in a later deployment. Use the ` write-manifest ` command to do this.
320322
321323The ` write-manifest ` command will also create a ` requirements.txt ` file, if it does
322324not already exist or the ` --force-generate ` option is specified. It will contain
@@ -392,7 +394,7 @@ is trusted by your Jupyter Notebook server, API client or user's browser, then y
392394don't need to do anything special. You can test this out with the ` details ` command:
393395
394396``` bash
395- rsconnect details --api-key my-api-key --server https://my. connect.server :3939
397+ rsconnect details --api-key my-api-key --server https://connect.example.org :3939
396398```
397399
398400If this fails with a TLS Certificate Validation error, then you have two options.
@@ -401,22 +403,22 @@ If this fails with a TLS Certificate Validation error, then you have two options
401403 RStudio Connect server. This will enable ` rsconnect ` to securely validate the
402404 server's TLS certificate.
403405
404- ```bash
405- rsconnect details \
406- --api-key my-api-key \
407- --server https://my. connect.server :3939 \
408- --cacert /path/to/certificate.pem
409- ```
406+ ``` bash
407+ rsconnect details \
408+ --api-key my-api-key \
409+ --server https://connect.example.org :3939 \
410+ --cacert /path/to/certificate.pem
411+ ```
410412
411413* RStudio Connect is in " insecure mode" . This disables TLS certificate verification,
412414 which results in a less secure connection.
413415
414- ```bash
415- rsconnect add \
416- --api-key my-api-key \
417- --server https://my. connect.server :3939 \
418- --insecure
419- ```
416+ ` ` ` bash
417+ rsconnect add \
418+ --api-key my-api-key \
419+ --server https://connect.example.org :3939 \
420+ --insecure
421+ ` ` `
420422
421423Once you work out the combination of options that allow you to successfully work with
422424an instance of RStudio Connect, you' ll probably want to use the `add` command to have
0 commit comments