Metadata-Version: 2.1
Name: rsconnect_python
Version: 1.24.0
Summary: Python integration with Posit Connect
Author-email: Michael Marchetti <mike@posit.co>
License: ### GNU GENERAL PUBLIC LICENSE
        
        Version 2, June 1991
        
            Copyright (C) 1989, 1991 Free Software Foundation, Inc.
            51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
        
            Everyone is permitted to copy and distribute verbatim copies
            of this license document, but changing it is not allowed.
        
        ### Preamble
        
        The licenses for most software are designed to take away your freedom
        to share and change it. By contrast, the GNU General Public License is
        intended to guarantee your freedom to share and change free
        software--to make sure the software is free for all its users. This
        General Public License applies to most of the Free Software
        Foundation's software and to any other program whose authors commit to
        using it. (Some other Free Software Foundation software is covered by
        the GNU Lesser General Public License instead.) You can apply it to
        your programs, too.
        
        When we speak of free software, we are referring to freedom, not
        price. Our General Public Licenses are designed to make sure that you
        have the freedom to distribute copies of free software (and charge for
        this service if you wish), that you receive source code or can get it
        if you want it, that you can change the software or use pieces of it
        in new free programs; and that you know you can do these things.
        
        To protect your rights, we need to make restrictions that forbid
        anyone to deny you these rights or to ask you to surrender the rights.
        These restrictions translate to certain responsibilities for you if
        you distribute copies of the software, or if you modify it.
        
        For example, if you distribute copies of such a program, whether
        gratis or for a fee, you must give the recipients all the rights that
        you have. You must make sure that they, too, receive or can get the
        source code. And you must show them these terms so they know their
        rights.
        
        We protect your rights with two steps: (1) copyright the software, and
        (2) offer you this license which gives you legal permission to copy,
        distribute and/or modify the software.
        
        Also, for each author's protection and ours, we want to make certain
        that everyone understands that there is no warranty for this free
        software. If the software is modified by someone else and passed on,
        we want its recipients to know that what they have is not the
        original, so that any problems introduced by others will not reflect
        on the original authors' reputations.
        
        Finally, any free program is threatened constantly by software
        patents. We wish to avoid the danger that redistributors of a free
        program will individually obtain patent licenses, in effect making the
        program proprietary. To prevent this, we have made it clear that any
        patent must be licensed for everyone's free use or not licensed at
        all.
        
        The precise terms and conditions for copying, distribution and
        modification follow.
        
        ### TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
        
        **0.** This License applies to any program or other work which
        contains a notice placed by the copyright holder saying it may be
        distributed under the terms of this General Public License. The
        "Program", below, refers to any such program or work, and a "work
        based on the Program" means either the Program or any derivative work
        under copyright law: that is to say, a work containing the Program or
        a portion of it, either verbatim or with modifications and/or
        translated into another language. (Hereinafter, translation is
        included without limitation in the term "modification".) Each licensee
        is addressed as "you".
        
        Activities other than copying, distribution and modification are not
        covered by this License; they are outside its scope. The act of
        running the Program is not restricted, and the output from the Program
        is covered only if its contents constitute a work based on the Program
        (independent of having been made by running the Program). Whether that
        is true depends on what the Program does.
        
        **1.** You may copy and distribute verbatim copies of the Program's
        source code as you receive it, in any medium, provided that you
        conspicuously and appropriately publish on each copy an appropriate
        copyright notice and disclaimer of warranty; keep intact all the
        notices that refer to this License and to the absence of any warranty;
        and give any other recipients of the Program a copy of this License
        along with the Program.
        
        You may charge a fee for the physical act of transferring a copy, and
        you may at your option offer warranty protection in exchange for a
        fee.
        
        **2.** You may modify your copy or copies of the Program or any
        portion of it, thus forming a work based on the Program, and copy and
        distribute such modifications or work under the terms of Section 1
        above, provided that you also meet all of these conditions:
        
        
        **a)** You must cause the modified files to carry prominent notices
        stating that you changed the files and the date of any change.
        
        
        **b)** You must cause any work that you distribute or publish, that in
        whole or in part contains or is derived from the Program or any part
        thereof, to be licensed as a whole at no charge to all third parties
        under the terms of this License.
        
        
        **c)** If the modified program normally reads commands interactively
        when run, you must cause it, when started running for such interactive
        use in the most ordinary way, to print or display an announcement
        including an appropriate copyright notice and a notice that there is
        no warranty (or else, saying that you provide a warranty) and that
        users may redistribute the program under these conditions, and telling
        the user how to view a copy of this License. (Exception: if the
        Program itself is interactive but does not normally print such an
        announcement, your work based on the Program is not required to print
        an announcement.)
        
        These requirements apply to the modified work as a whole. If
        identifiable sections of that work are not derived from the Program,
        and can be reasonably considered independent and separate works in
        themselves, then this License, and its terms, do not apply to those
        sections when you distribute them as separate works. But when you
        distribute the same sections as part of a whole which is a work based
        on the Program, the distribution of the whole must be on the terms of
        this License, whose permissions for other licensees extend to the
        entire whole, and thus to each and every part regardless of who wrote
        it.
        
        Thus, it is not the intent of this section to claim rights or contest
        your rights to work written entirely by you; rather, the intent is to
        exercise the right to control the distribution of derivative or
        collective works based on the Program.
        
        In addition, mere aggregation of another work not based on the Program
        with the Program (or with a work based on the Program) on a volume of
        a storage or distribution medium does not bring the other work under
        the scope of this License.
        
        **3.** You may copy and distribute the Program (or a work based on it,
        under Section 2) in object code or executable form under the terms of
        Sections 1 and 2 above provided that you also do one of the following:
        
        
        **a)** Accompany it with the complete corresponding machine-readable
        source code, which must be distributed under the terms of Sections 1
        and 2 above on a medium customarily used for software interchange; or,
        
        
        **b)** Accompany it with a written offer, valid for at least three
        years, to give any third party, for a charge no more than your cost of
        physically performing source distribution, a complete machine-readable
        copy of the corresponding source code, to be distributed under the
        terms of Sections 1 and 2 above on a medium customarily used for
        software interchange; or,
        
        
        **c)** Accompany it with the information you received as to the offer
        to distribute corresponding source code. (This alternative is allowed
        only for noncommercial distribution and only if you received the
        program in object code or executable form with such an offer, in
        accord with Subsection b above.)
        
        The source code for a work means the preferred form of the work for
        making modifications to it. For an executable work, complete source
        code means all the source code for all modules it contains, plus any
        associated interface definition files, plus the scripts used to
        control compilation and installation of the executable. However, as a
        special exception, the source code distributed need not include
        anything that is normally distributed (in either source or binary
        form) with the major components (compiler, kernel, and so on) of the
        operating system on which the executable runs, unless that component
        itself accompanies the executable.
        
        If distribution of executable or object code is made by offering
        access to copy from a designated place, then offering equivalent
        access to copy the source code from the same place counts as
        distribution of the source code, even though third parties are not
        compelled to copy the source along with the object code.
        
        **4.** You may not copy, modify, sublicense, or distribute the Program
        except as expressly provided under this License. Any attempt otherwise
        to copy, modify, sublicense or distribute the Program is void, and
        will automatically terminate your rights under this License. However,
        parties who have received copies, or rights, from you under this
        License will not have their licenses terminated so long as such
        parties remain in full compliance.
        
        **5.** You are not required to accept this License, since you have not
        signed it. However, nothing else grants you permission to modify or
        distribute the Program or its derivative works. These actions are
        prohibited by law if you do not accept this License. Therefore, by
        modifying or distributing the Program (or any work based on the
        Program), you indicate your acceptance of this License to do so, and
        all its terms and conditions for copying, distributing or modifying
        the Program or works based on it.
        
        **6.** Each time you redistribute the Program (or any work based on
        the Program), the recipient automatically receives a license from the
        original licensor to copy, distribute or modify the Program subject to
        these terms and conditions. You may not impose any further
        restrictions on the recipients' exercise of the rights granted herein.
        You are not responsible for enforcing compliance by third parties to
        this License.
        
        **7.** If, as a consequence of a court judgment or allegation of
        patent infringement or for any other reason (not limited to patent
        issues), conditions are imposed on you (whether by court order,
        agreement or otherwise) that contradict the conditions of this
        License, they do not excuse you from the conditions of this License.
        If you cannot distribute so as to satisfy simultaneously your
        obligations under this License and any other pertinent obligations,
        then as a consequence you may not distribute the Program at all. For
        example, if a patent license would not permit royalty-free
        redistribution of the Program by all those who receive copies directly
        or indirectly through you, then the only way you could satisfy both it
        and this License would be to refrain entirely from distribution of the
        Program.
        
        If any portion of this section is held invalid or unenforceable under
        any particular circumstance, the balance of the section is intended to
        apply and the section as a whole is intended to apply in other
        circumstances.
        
        It is not the purpose of this section to induce you to infringe any
        patents or other property right claims or to contest validity of any
        such claims; this section has the sole purpose of protecting the
        integrity of the free software distribution system, which is
        implemented by public license practices. Many people have made
        generous contributions to the wide range of software distributed
        through that system in reliance on consistent application of that
        system; it is up to the author/donor to decide if he or she is willing
        to distribute software through any other system and a licensee cannot
        impose that choice.
        
        This section is intended to make thoroughly clear what is believed to
        be a consequence of the rest of this License.
        
        **8.** If the distribution and/or use of the Program is restricted in
        certain countries either by patents or by copyrighted interfaces, the
        original copyright holder who places the Program under this License
        may add an explicit geographical distribution limitation excluding
        those countries, so that distribution is permitted only in or among
        countries not thus excluded. In such case, this License incorporates
        the limitation as if written in the body of this License.
        
        **9.** The Free Software Foundation may publish revised and/or new
        versions of the General Public License from time to time. Such new
        versions will be similar in spirit to the present version, but may
        differ in detail to address new problems or concerns.
        
        Each version is given a distinguishing version number. If the Program
        specifies a version number of this License which applies to it and
        "any later version", you have the option of following the terms and
        conditions either of that version or of any later version published by
        the Free Software Foundation. If the Program does not specify a
        version number of this License, you may choose any version ever
        published by the Free Software Foundation.
        
        **10.** If you wish to incorporate parts of the Program into other
        free programs whose distribution conditions are different, write to
        the author to ask for permission. For software which is copyrighted by
        the Free Software Foundation, write to the Free Software Foundation;
        we sometimes make exceptions for this. Our decision will be guided by
        the two goals of preserving the free status of all derivatives of our
        free software and of promoting the sharing and reuse of software
        generally.
        
        **NO WARRANTY**
        
        **11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
        WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
        EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
        OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
        KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
        PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
        PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
        THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
        
        **12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
        WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
        AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU
        FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
        CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
        PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
        RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
        FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF
        SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
        DAMAGES.
        
        ### END OF TERMS AND CONDITIONS
        
        ### How to Apply These Terms to Your New Programs
        
        If you develop a new program, and you want it to be of the greatest
        possible use to the public, the best way to achieve this is to make it
        free software which everyone can redistribute and change under these
        terms.
        
        To do so, attach the following notices to the program. It is safest to
        attach them to the start of each source file to most effectively
        convey the exclusion of warranty; and each file should have at least
        the "copyright" line and a pointer to where the full notice is found.
        
            one line to give the program's name and an idea of what it does.
            Copyright (C) yyyy  name of author
        
            This program is free software; you can redistribute it and/or
            modify it under the terms of the GNU General Public License
            as published by the Free Software Foundation; either version 2
            of the License, or (at your option) any later version.
        
            This program is distributed in the hope that it will be useful,
            but WITHOUT ANY WARRANTY; without even the implied warranty of
            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
            GNU General Public License for more details.
        
            You should have received a copy of the GNU General Public License
            along with this program; if not, write to the Free Software
            Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
        
        Also add information on how to contact you by electronic and paper
        mail.
        
        If the program is interactive, make it output a short notice like this
        when it starts in an interactive mode:
        
            Gnomovision version 69, Copyright (C) year name of author
            Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
            type `show w'.  This is free software, and you are welcome
            to redistribute it under certain conditions; type `show c'
            for details.
        
        The hypothetical commands \`show w' and \`show c' should show the
        appropriate parts of the General Public License. Of course, the
        commands you use may be called something other than \`show w' and
        \`show c'; they could even be mouse-clicks or menu items--whatever
        suits your program.
        
        You should also get your employer (if you work as a programmer) or
        your school, if any, to sign a "copyright disclaimer" for the program,
        if necessary. Here is a sample; alter the names:
        
            Yoyodyne, Inc., hereby disclaims all copyright
            interest in the program `Gnomovision'
            (which makes passes at compilers) written
            by James Hacker.
        
            signature of Ty Coon, 1 April 1989
            Ty Coon, President of Vice
        
        This General Public License does not permit incorporating your program
        into proprietary programs. If your program is a subroutine library,
        you may consider it more useful to permit linking proprietary
        applications with the library. If this is what you want to do, use the
        [GNU Lesser General Public
        License](https://www.gnu.org/licenses/lgpl.html) instead of this
        License.
        
Project-URL: Repository, http://github.com/posit-dev/rsconnect-python
Project-URL: Documentation, https://docs.posit.co/rsconnect-python
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: typing-extensions >=4.10.0
Requires-Dist: pip >=10.0.0
Requires-Dist: semver <3.0.0,>=2.0.0
Requires-Dist: pyjwt >=2.4.0
Requires-Dist: click >=8.0.0
Provides-Extra: test
Requires-Dist: black ==24.3.0 ; extra == 'test'
Requires-Dist: coverage ; extra == 'test'
Requires-Dist: flake8-pyproject ; extra == 'test'
Requires-Dist: flake8 ; extra == 'test'
Requires-Dist: httpretty ; extra == 'test'
Requires-Dist: ipykernel ; extra == 'test'
Requires-Dist: nbconvert ; extra == 'test'
Requires-Dist: pyright ; extra == 'test'
Requires-Dist: pytest-cov ; extra == 'test'
Requires-Dist: pytest ; extra == 'test'
Requires-Dist: setuptools >=61 ; extra == 'test'
Requires-Dist: setuptools-scm[toml] >=3.4 ; extra == 'test'
Requires-Dist: twine ; extra == 'test'
Requires-Dist: types-Flask ; extra == 'test'

# The rsconnect-python CLI

This package provides a CLI (command-line interface) for interacting
with and deploying to Posit Connect. This is also used by the
[`rsconnect-jupyter`](https://github.com/rstudio/rsconnect-jupyter) package to deploy
Jupyter notebooks via the Jupyter web console. Many types of content supported by Posit
Connect may be deployed by this package, including WSGI-style APIs, Dash, Streamlit, and
Bokeh applications.

Content types not directly supported by the CLI may also be deployed if they include a
prepared `manifest.json` file. See ["Deploying R or Other
Content"](#deploying-r-or-other-content) for details.


## Deploying Python Content to Posit Connect

Posit Connect supports the deployment of Jupyter notebooks, Python APIs (such as
those based on Flask or FastAPI) and apps (such as Dash, Streamlit, and Bokeh apps).
Much like deploying R
content to Posit Connect, there are some caveats to understand when replicating your
environment on the Posit Connect server:

Posit Connect insists on matching `<MAJOR.MINOR>` versions of Python. For example,
a server with only Python 3.9 installed will fail to match content deployed with
Python 3.8. Your administrator may also enable exact Python version matching which
will be stricter and require matching major, minor, and patch versions. For more
information see the [Posit Connect Admin Guide chapter titled Python Version
Matching](https://docs.posit.co/connect/admin/python/#python-version-matching).

### Installation

To install `rsconnect-python` from PYPI, you may use any python package manager such as
pip:

```bash
pip install rsconnect-python
```

You may also build and install a wheel directly from a repository clone:

```bash
git clone https://github.com/posit-dev/rsconnect-python.git
cd rsconnect-python
pip install pipenv
make dist
pip install ./dist/rsconnect_python-*.whl
```

### Using the rsconnect CLI

Here's an example command that deploys a Jupyter notebook to Posit Connect.

```bash
rsconnect deploy notebook \
    --server https://connect.example.org \
    --api-key my-api-key \
    my-notebook.ipynb
```

> **Note**
> The examples here use long command line options, but there are short
> options (`-s`, `-k`, etc.) available also. Run `rsconnect deploy notebook --help`
> for details.

### Setting up `rsconnect` CLI auto-completion

If you would like to use your shell's tab completion support with the `rsconnect`
command, use the command below for the shell you are using.

#### `bash`

If you are using the `bash` shell, use this to enable tab completion.

```bash
#~/.bashrc
eval "$(_RSCONNECT_COMPLETE=source rsconnect)"
```

#### `zsh`

If you are using the `zsh` shell, use this to enable tab completion.

```zsh
#~/.zshrc
eval "$(_RSCONNECT_COMPLETE=source_zsh rsconnect)"
```

If you get `command not found: compdef`, you need to add the following lines to your
`.zshrc` before the completion setup:

```zsh
#~/.zshrc
autoload -Uz compinit
compinit
```

### Managing Server Information

The information used by the `rsconnect` command to communicate with a Posit Connect
server can be tedious to repeat on every command. To help, the CLI supports the idea
of saving this information, making it usable by a simple nickname.

> **Warning**
> One item of information saved is the API key used to authenticate with
> Posit Connect. Although the file where this information is saved is marked as
> accessible by the owner only, it's important to remember that the key is present
> in the file as plain text so care must be taken to prevent any unauthorized access
> to the server information file.

#### TLS Support and Posit Connect

Usually, a Posit Connect server will be set up to be accessed in a secure manner,
using the `https` protocol rather than simple `http`. If Posit Connect is set up
with a self-signed certificate, you will need to include the `--insecure` flag on
all commands. If Posit Connect is set up to require a client-side certificate chain,
you will need to include the `--cacert` option that points to your certificate
authority (CA) trusted certificates file. Both of these options can be saved along
with the URL and API Key for a server.

> **Note**
> When certificate information is saved for the server, the specified file
> is read and its _contents_ are saved under the server's nickname. If the CA file's
> contents are ever changed, you will need to add the server information again.

See the [Network Options](#network-options) section for more details about these options.

#### Remembering Server Information

Use the `add` command to store information about a Posit Connect server:

```bash
rsconnect add \
    --api-key my-api-key \
    --server https://connect.example.org \
    --name myserver
```

> **Note**
> The `rsconnect` CLI will verify that the serve URL and API key
> are valid. If either is found not to be, no information will be saved.

If any of the access information for the server changes, simply rerun the
`add` command with the new information and it will replace the original
information.

Once the server's information is saved, you can refer to it by its nickname:

```bash
rsconnect deploy notebook --name myserver my-notebook.ipynb
```

If there is information for only one server saved, this will work too:

```bash
rsconnect deploy notebook my-notebook.ipynb
```

#### Listing Server Information

You can see the list of saved server information with:

```
rsconnect list
```

#### Removing Server Information

You can remove information about a server with:

```
rsconnect remove --name myserver
```

Removing may be done by its nickname (`--name`) or URL (`--server`).

### Verifying Server Information

You can verify that a URL refers to a running instance of Posit Connect by using
the `details` command:

```bash
rsconnect details --server https://connect.example.org
```

In this form, `rsconnect` will only tell you whether the URL given does, in fact, refer
to a running Posit Connect instance. If you include a valid API key:

```bash
rsconnect details --server https://connect.example.org --api-key my-api-key
```

the tool will provide the version of Posit Connect (if the server is configured to
divulge that information) and environmental information including versions of Python
that are installed on the server.

You can also use nicknames with the `details` command if you want to verify that the
stored information is still valid.

### Notebook Deployment Options

There are a variety of options available to you when deploying a Jupyter notebook to
Posit Connect.

#### Including Extra Files

You can include extra files in the deployment bundle to make them available when your
notebook is run by the Posit Connect server. Just specify them on the command line
after the notebook file:

```bash
rsconnect deploy notebook my-notebook.ipynb data.csv
```

#### Package Dependencies

If a `requirements.txt` file exists in the same directory as the notebook file, it will
be included in the bundle. It must specify the package dependencies needed to execute
the notebook. Posit Connect will reconstruct the Python environment using the
specified package list.

If there is no `requirements.txt` file or the `--force-generate` option is specified,
the package dependencies will be determined from the current Python environment, or
from an alternative Python executable specified via the `--python` option:

```bash
rsconnect deploy notebook --python /path/to/python my-notebook.ipynb
```

You can see the packages list that will be included by running `pip list --format=freeze` yourself,
ensuring that you use the same Python that you use to run your Jupyter Notebook:

```bash
/path/to/python -m pip list --format=freeze
```

#### Static (Snapshot) Deployment

By default, `rsconnect` deploys the original notebook with all its source code. This
enables the Posit Connect server to re-run the notebook upon request or on a schedule.

If you just want to publish an HTML snapshot of the notebook, you can use the `--static`
option. This will cause `rsconnect` to execute your notebook locally to produce the HTML
file, then publish the HTML file to the Posit Connect server:

```bash
rsconnect deploy notebook --static my-notebook.ipynb
```

### Creating a Manifest for Future Deployment

You can create a `manifest.json` file for a Jupyter Notebook, then use that manifest
in a later deployment. Use the `write-manifest` command to do this.

The `write-manifest` command will also create a `requirements.txt` file, if it does
not already exist or the `--force-generate` option is specified. It will contain the
package dependencies from the current Python environment, or from an alternative
Python executable specified in the `--python` option.

Here is an example of the `write-manifest` command:

```bash
rsconnect write-manifest notebook my-notebook.ipynb
```

> **Note**
> Manifests for static (pre-rendered) notebooks cannot be created.

### API/Application Deployment Options

You can deploy a variety of APIs and applications using sub-commands of the
`rsconnect deploy` command.

* `api`: WSGI-compliant APIs (e.g., `bottle`, `falcon`, `flask`, `flask-restx`, `flasgger`, `pycnic`).
* `flask`: Flask APIs (_Note: `flask` is an alias of `api`._).
* `fastapi`: ASGI-compliant APIs (e.g, `fastapi`, `quart`, `sanic`, `starlette`)
* `dash`: Python Dash apps
* `streamlit`: Streamlit apps
* `bokeh`: Bokeh server apps

All options below apply equally to the `api`, `fastapi`, `dash`, `streamlit`,
and `bokeh` sub-commands.

#### Including Extra Files

You can include extra files in the deployment bundle to make them available when your
API or application is run by the Posit Connect server. Just specify them on the
command line after the API or application directory:

```bash
rsconnect deploy api flask-api/ data.csv
```

Since deploying an API or application starts at a directory level, there will be times
when some files under that directory subtree should not be included in the deployment
or manifest. Use the `--exclude` option to specify files or directories to exclude.

```bash
rsconnect deploy dash --exclude dash-app-venv --exclude TODO.txt dash-app/
```

You can exclude a directory by naming it:
```bash
rsconnect deploy dash --exclude dash-app-venv --exclude output/ dash-app/
```

The `--exclude` option may be repeated, and may include a glob pattern.
You should always quote a glob pattern so that it will be passed to `rsconnect` as-is
instead of letting the shell expand it. If a file is specifically listed as an extra
file that also matches an exclusion pattern, the file will still be included in the
deployment (i.e., extra files take precedence).

```bash
rsconnect deploy dash --exclude dash-app-venv --exclude “*.txt” dash-app/
```

The following shows an example of an extra file taking precedence:

```bash
rsconnect deploy dash --exclude “*.csv” dash-app/ important_data.csv
```

The "`**`" glob pattern will recursively match all files and directories,
while "`*`" only matches files. The "`**`" pattern is useful with complicated
project hierarchies where enumerating the _included_ files is simpler than
listing the _exclusions_.

```bash
rsconnect deploy quarto . _quarto.yml index.qmd requirements.txt --exclude "**"
```

Some directories are excluded by default, to prevent bundling and uploading files that are not needed or might interfere with the deployment process:

```
.Rproj.user
.env
.git
.svn
.venv
__pycache__
env
packrat
renv
rsconnect-python
rsconnect
venv
```

Any directory that appears to be a Python virtual environment (by containing
`bin/python`) will also be excluded.


#### Package Dependencies

If a `requirements.txt` file exists in the API/application directory, it will be
included in the bundle. It must specify the package dependencies needed to execute
the API or application. Posit Connect will reconstruct the Python environment using
the specified package list.

If there is no `requirements.txt` file or the `--force-generate` option is specified,
the package dependencies will be determined from the current Python environment, or
from an alternative Python executable specified via the `--python` option:

```bash
rsconnect deploy api --python /path/to/python my-api/
```

You can see the packages list that will be included by running `pip list --format=freeze` yourself,
ensuring that you use the same Python that you use to run your API or application:

```bash
/path/to/python -m pip list --format=freeze
```

### Creating a Manifest for Future Deployment

You can create a `manifest.json` file for an API or application, then use that
manifest in a later deployment. Use the `write-manifest` command to do this.

The `write-manifest` command will also create a `requirements.txt` file, if it does
not already exist or the `--force-generate` option is specified. It will contain
the package dependencies from the current Python environment, or from an alternative
Python executable specified in the `--python` option.

Here is an example of the `write-manifest` command:

```bash
rsconnect write-manifest api my-api/
```

### Deploying R or Other Content

You can deploy other content that has an existing Posit Connect `manifest.json`
file. For example, if you download and unpack a source bundle from Posit Connect,
you can deploy the resulting directory. The options are similar to notebook or
API/application deployment; see `rsconnect deploy manifest --help` for details.

Here is an example of the `deploy manifest` command:

```bash
rsconnect deploy manifest /path/to/manifest.json
```

> **Note**
> In this case, the existing content is deployed as-is. Python environment
> inspection and notebook pre-rendering, if needed, are assumed to be done already
> and represented in the manifest.

The argument to `deploy manifest` may also be a directory so long as that directory
contains a `manifest.json` file.

If you have R content but don't have a `manifest.json` file, you can use the RStudio
IDE to create the manifest. See the help for the `rsconnect::writeManifest` R function:

```r
install.packages('rsconnect')
library(rsconnect)
?rsconnect::writeManifest
```

### Options for All Types of Deployments

These options apply to any type of content deployment.

#### Title

The title of the deployed content is, by default, derived from the filename. For
example, if you deploy `my-notebook.ipynb`, the title will be `my-notebook`. To change
this, use the `--title` option:

```
rsconnect deploy notebook --title "My Notebook" my-notebook.ipynb
```

When using `rsconnect deploy api`, `rsconnect deploy fastapi`, `rsconnect deploy dash`,
`rsconnect deploy streamlit`, or `rsconnect deploy bokeh`, the title is derived from the directory
containing the API or application.

When using `rsconnect deploy manifest`, the title is derived from the primary
filename referenced in the manifest.

#### Verification After Deployment
After deploying your content, rsconnect accesses the deployed content
to verify that the deployment is live. This is done with a `GET` request
to the content, without parameters. The request is
considered successful if there isn't a 5xx code returned. Errors like
400 Bad Request or 405 Method Not Allowed because not all apps support `GET /`.
For cases where this is not desired, use the `--no-verify` flag on the command line.

### Environment variables
You can set environment variables during deployment. Their names and values will be
passed to Posit Connect during deployment so you can use them in your code. Note that
if you are using `rsconnect` to deploy to shinyapps.io, environment variable management
is not supported on that platform.

For example, if `notebook.ipynb` contains
```python
print(os.environ["MYVAR"])
```

You can set the value of `MYVAR` that will be set when your code runs in Posit Connect
using the `-E/--environment` option:
```bash
rsconnect deploy notebook --environment MYVAR='hello world' notebook.ipynb
```

To avoid exposing sensitive values on the command line, you can specify
a variable without a value. In this case, it will use the value from the
environment in which rsconnect-python is running:
```bash
export SECRET_KEY=12345

rsconnect deploy notebook --environment SECRET_KEY notebook.ipynb
```

If you specify environment variables when updating an existing deployment,
new values will be set for the variables you provided. Other variables will
remain unchanged. If you don't specify any variables, all of the existing
variables will remain unchanged.

Environment variables are set on the content item before the content bundle
is uploaded and deployed. If the deployment fails, the new environment variables
will still take effect.

### Network Options

When specifying information that `rsconnect` needs to be able to interact with Posit
Connect, you can tailor how transport layer security is performed.

#### TLS/SSL Certificates

Posit Connect servers can be configured to use TLS/SSL. If your server's certificate
is trusted by your Jupyter Notebook server, API client or user's browser, then you
don't need to do anything special. You can test this out with the `details` command:

```bash
rsconnect details \
    --api-key my-api-key \
    --server https://connect.example.org:3939
```

If this fails with a TLS Certificate Validation error, then you have two options.

* Provide the Root CA certificate that is at the root of the signing chain for your
  Posit Connect server. This will enable `rsconnect` to securely validate the
  server's TLS certificate.

    ```bash
    rsconnect details \
        --api-key my-api-key \
        --server https://connect.example.org \
        --cacert /path/to/certificate.pem
    ```

* Posit Connect is in "insecure mode". This disables TLS certificate verification,
  which results in a less secure connection.

    ```bash
    rsconnect add \
        --api-key my-api-key \
        --server https://connect.example.org \
        --insecure
    ```

Once you work out the combination of options that allow you to successfully work with
an instance of Posit Connect, you'll probably want to use the `add` command to have
`rsconnect` remember those options and allow you to just use a nickname.

### Updating a Deployment

If you deploy a file again to the same server, `rsconnect` will update the previous
deployment. This means that you can keep running `rsconnect deploy notebook my-notebook.ipynb`
as you develop new versions of your notebook. The same applies to other Python content
types.

#### Forcing a New Deployment

To bypass this behavior and force a new deployment, use the `--new` option:

```bash
rsconnect deploy dash --new my-app/
```

#### Updating a Different Deployment

If you want to update an existing deployment but don't have the saved deployment data,
you can provide the app's numeric ID or GUID on the command line:

```bash
rsconnect deploy notebook --app-id 123456 my-notebook.ipynb
```

You must be the owner of the target deployment, or a collaborator with permission to
change the content. The type of content (static notebook, notebook with source code,
API, or application) must match the existing deployment.

> **Note**
> There is no confirmation required to update a deployment. If you do so
> accidentally, use the "Source Versions" dialog in the Posit Connect dashboard to
> activate the previous version and remove the erroneous one.

##### Finding the App ID

The App ID associated with a piece of content you have previously deployed from the
`rsconnect` command line interface can be found easily by querying the deployment
information using the `info` command. For more information, see the
[Showing the Deployment Information](#showing-the-deployment-information) section.

If the content was deployed elsewhere or `info` does not return the correct App ID,
but you can open the content on Posit Connect, find the content and open it in a
browser. The URL in your browser's location bar will contain `#/apps/NNN` where `NNN`
is your App ID. The GUID identifier for the app may be found on the **Info** tab for
the content in the Posit Connect UI.

#### Showing the Deployment Information

You can see the information that the `rsconnect` command has saved for the most recent
deployment with the `info` command:

```bash
rsconnect info my-notebook.ipynb
```

If you have deployed to multiple servers, the most recent deployment information for
each server will be shown. This command also displays the path to the file where the
deployment data is stored.

## Stored Information Files

Stored information files are stored in a platform-specific directory:

| Platform | Location                                                           |
| -------- | ------------------------------------------------------------------ |
| Mac      | `$HOME/Library/Application Support/rsconnect-python/`              |
| Linux    | `$HOME/.rsconnect-python/` or `$XDG_CONFIG_HOME/rsconnect-python/` |
| Windows  | `$APPDATA/rsconnect-python`                                        |

Remembered server information is stored in the `servers.json` file in that directory.

### Deployment Data

After a deployment is completed, information about the deployment is saved
to enable later redeployment. This data is stored alongside the deployed file,
in an `rsconnect-python` subdirectory, if possible. If that location is not writable
during deployment, then the deployment data will be stored in the global configuration
directory specified above.

<div style="display:none">
Generated from <code>rsconnect-python {{ rsconnect_python.version }}</code>
</div>

### Hide Jupyter Notebook Input Code Cells

The user can render a Jupyter notebook without its corresponding input code cells by passing the '--hide-all-input' flag through the cli:

```bash
rsconnect deploy notebook \
    --server https://connect.example.org \
    --api-key my-api-key \
    --hide-all-input \
    my-notebook.ipynb
```

To selectively hide input cells in a Jupyter notebook, the user needs to follow a two step process:
1. tag cells with the 'hide_input' tag,
2. then pass the ' --hide-tagged-input' flag through the cli:

```bash
rsconnect deploy notebook \
    --server https://connect.example.org \
    --api-key my-api-key \
    --hide-tagged-input \
    my-notebook.ipynb
```

By default, rsconnect-python does not install Jupyter notebook related depenencies. These dependencies are installed via rsconnect-jupyter. When the user is using the hide input features in rsconnect-python by itself without rsconnect-jupyter, he/she needs to install the following package depenecies:

```
notebook
nbformat
nbconvert>=5.6.1
```

## Content subcommands

rsconnect-python supports multiple options for interacting with Posit Connect's
`/v1/content` API. Both administrators and publishers can use the content subcommands
to search, download, and rebuild content on Posit Connect without needing to access the
dashboard from a browser.

> **Note**
> The `rsconnect content` CLI subcommands are intended to be easily scriptable.
> The default output format is `JSON` so that the results can be easily piped into
> other command line utilities like [`jq`](https://stedolan.github.io/jq/) for further post-processing.

```bash
rsconnect content --help
# Usage: rsconnect content [OPTIONS] COMMAND [ARGS]...

#   Interact with Posit Connect's content API.

# Options:
#   --help  Show this message and exit.

# Commands:
#   build            Build content on Posit Connect.
#   describe         Describe a content item on Posit Connect.
#   download-bundle  Download a content item's source bundle.
#   search           Search for content on Posit Connect.
```

### Content Search

The `rsconnect content search` subcommands can be used by administrators and publishers
to find specific content on a given Posit Connect server. The search returns
metadata for each content item that meets the search criteria.

```bash
rsconnect content search --help
# Usage: rsconnect content search [OPTIONS]

# Options:
#   -n, --name TEXT                 The nickname of the Posit Connect server.
#   -s, --server TEXT               The URL for the Posit Connect server.
#   -k, --api-key TEXT              The API key to use to authenticate with
#                                   Posit Connect.

#   -i, --insecure                  Disable TLS certification/host validation.
#   -c, --cacert FILENAME           The path to trusted TLS CA certificates.
#   --published                     Search only published content.
#   --unpublished                   Search only unpublished content.
#   --content-type [unknown|shiny|rmd-static|rmd-shiny|static|api|tensorflow-saved-model|jupyter-static|python-api|python-dash|python-streamlit|python-bokeh|python-fastapi|quarto-shiny|quarto-static]
#                                   Filter content results by content type.
#   --r-version VERSIONSEARCHFILTER
#                                   Filter content results by R version.
#   --py-version VERSIONSEARCHFILTER
#                                   Filter content results by Python version.
#   --title-contains TEXT           Filter content results by title.
#   --order-by [created|last_deployed]
#                                   Order content results.
#   -v, --verbose                   Print detailed messages.
#   --help                          Show this message and exit.

rsconnect content search
# [
#   {
#     "max_conns_per_process": null,
#     "content_category": "",
#     "load_factor": null,
#     "cluster_name": "Local",
#     "description": "",
#     "bundle_id": "142",
#     "image_name": null,
#     "r_version": null,
#     "content_url": "https://connect.example.org:3939/content/4ffc819c-065c-420c-88eb-332db1133317/",
#     "connection_timeout": null,
#     "min_processes": null,
#     "last_deployed_time": "2021-12-02T18:09:11Z",
#     "name": "logs-api-python",
#     "title": "logs-api-python",
#     "created_time": "2021-07-19T19:17:32Z",
#     "read_timeout": null,
#     "guid": "4ffc819c-065c-420c-88eb-332db1133317",
#     "parameterized": false,
#     "run_as": null,
#     "py_version": "3.8.2",
#     "idle_timeout": null,
#     "app_role": "owner",
#     "access_type": "acl",
#     "app_mode": "python-api",
#     "init_timeout": null,
#     "id": "18",
#     "quarto_version": null,
#     "dashboard_url": "https://connect.example.org:3939/connect/#/apps/4ffc819c-065c-420c-88eb-332db1133317",
#     "run_as_current_user": false,
#     "owner_guid": "edf26318-0027-4d9d-bbbb-54703ebb1855",
#     "max_processes": null
#   },
#   ...
# ]
```

See [this section](#searching-for-content) for more comprehensive usage examples
of the available search flags.


### Content Build

> **Note**
> The `rsconnect content build` subcommand requires Posit Connect >= 2021.11.1

Posit Connect caches R and Python packages in the configured
[`Server.DataDir`](https://docs.posit.co/connect/admin/appendix/configuration/#Server.DataDir).
Under certain circumstances (examples below), these package caches can become stale
and need to be rebuilt. This refresh automatically occurs when a Posit Connect
user visits the content. You may wish to refresh some content before it is visited
because it is high priority or is not visited frequently (API content, emailed reports).
In these cases, it is possible to preemptively build specific content items using
the `rsconnect content build` subcommands. This way the user does not have to pay
the build cost when the content is accessed next.

The following are some common scenarios where performing a content build might be necessary:

- OS upgrade
- changes to gcc or libc libraries
- changes to Python or R installations
- switching from source to binary package repositories or vice versa

> **Note**
> The `content build` command is non-destructive, meaning that it does nothing to purge
> existing packrat/python package caches before a build. If you have an
> existing cache, it should be cleared prior to starting a content build.
> See the [migration documentation](https://docs.posit.co/connect/admin/appendix/cli/#migration) for details.

> **Note**
> You may use the [`rsconnect content search`](#content-search) subcommand to help
> identify high priority content items to build.

```bash
rsconnect content build --help
Usage: rsconnect content build [OPTIONS] COMMAND [ARGS]...

  Build content on Posit Connect. Requires Connect >= 2021.11.1

Options:
  --help  Show this message and exit.

Commands:
  add      Mark a content item for build. Use `build run` to invoke the build
           on the Connect server.

  history  Get the build history for a content item.
  logs     Print the logs for a content build.
  ls       List the content items that are being tracked for build on a given
           Connect server.

  rm       Remove a content item from the list of content that are tracked for
           build. Use `build ls` to view the tracked content.

  run      Start building content on a given Connect server.
```

To build a specific content item, first `add` it to the list of content that is
"tracked" for building using its GUID.

> **Note**
> Metadata for "tracked" content items is stored in a local directory called
> `rsconnect-build` which will be automatically created in your current working directory.
> You may set the environment variable `CONNECT_CONTENT_BUILD_DIR` to override this directory location.

```bash
rsconnect content build add --guid 4ffc819c-065c-420c-88eb-332db1133317
```

> **Note**
> See [this section](#add-to-build-from-search-results) for
> an example of how to add multiple content items in bulk, from the results
> of a `rsconnect content search` command.

To view all currently "tracked" content items, use the `rsconnect content build ls` subcommand.

```bash
rsconnect content build ls
```

To view only the "tracked" content items that have not yet been built, use the `--status NEEDS_BUILD` flag.

```bash
rsconnect content build ls --status NEEDS_BUILD
```

Once the content items have been added, you may initiate a build
using the `rsconnect content build run` subcommand. This command will attempt to
build all "tracked" content that has the status `NEEDS_BUILD`.

> To re-run failed builds, use `rsconnect content build run --retry`. This will build
all tracked content in any of the following states: `[NEEDS_BUILD, ABORTED, ERROR, RUNNING]`.

```bash
rsconnect content build run
# [INFO] 2021-12-14T13:02:45-0500 Initializing ContentBuildStore for https://connect.example.org:3939
# [INFO] 2021-12-14T13:02:45-0500 Starting content build (https://connect.example.org:3939)...
# [INFO] 2021-12-14T13:02:45-0500 Starting build: 4ffc819c-065c-420c-88eb-332db1133317
# [INFO] 2021-12-14T13:02:50-0500 Running = 1, Pending = 0, Success = 0, Error = 0
# [INFO] 2021-12-14T13:02:50-0500 Build succeeded: 4ffc819c-065c-420c-88eb-332db1133317
# [INFO] 2021-12-14T13:02:55-0500 Running = 0, Pending = 0, Success = 1, Error = 0
# [INFO] 2021-12-14T13:02:55-0500 1/1 content builds completed in 0:00:10
# [INFO] 2021-12-14T13:02:55-0500 Success = 1, Error = 0
# [INFO] 2021-12-14T13:02:55-0500 Content build complete.
```

Sometimes content builds will fail and require debugging by the publisher or administrator.
Use the `rsconnect content build ls` to identify content builds that resulted in errors
and inspect the build logs with the `rsconnect content build logs` subcommand.

```bash
rsconnect content build ls --status ERROR
# [INFO] 2021-12-14T13:07:32-0500 Initializing ContentBuildStore for https://connect.example.org:3939
# [
#   {
#     "rsconnect_build_status": "ERROR",
#     "last_deployed_time": "2021-12-02T18:09:11Z",
#     "owner_guid": "edf26318-0027-4d9d-bbbb-54703ebb1855",
#     "rsconnect_last_build_log": "/Users/david/code/posit/rsconnect-python/rsconnect-build/logs/connect_example_org_3939/4ffc819c-065c-420c-88eb-332db1133317/pZoqfBoi6BgpKde5.log",
#     "guid": "4ffc819c-065c-420c-88eb-332db1133317",
#     "rsconnect_build_task_result": {
#       "user_id": 1,
#       "error": "Cannot find compatible environment: no compatible Local environment with Python version 3.9.5",
#       "code": 1,
#       "finished": true,
#       "result": {
#         "data": "An error occurred while building the content",
#         "type": "build-failed-error"
#       },
#       "id": "pZoqfBoi6BgpKde5"
#     },
#     "dashboard_url": "https://connect.example.org:3939/connect/#/apps/4ffc819c-065c-420c-88eb-332db1133317",
#     "name": "logs-api-python",
#     "title": "logs-api-python",
#     "content_url": "https://connect.example.org:3939/content/4ffc819c-065c-420c-88eb-332db1133317/",
#     "bundle_id": "141",
#     "rsconnect_last_build_time": "2021-12-14T18:07:16Z",
#     "created_time": "2021-07-19T19:17:32Z",
#     "app_mode": "python-api"
#   }
# ]

rsconnect content build logs --guid 4ffc819c-065c-420c-88eb-332db1133317
# [INFO] 2021-12-14T13:09:27-0500 Initializing ContentBuildStore for https://connect.example.org:3939
# Building Python API...
# Cannot find compatible environment: no compatible Local environment with Python version 3.9.5
# Task failed. Task exited with status 1.
```

## Common Usage Examples

### Searching for content

The following are some examples of how publishers might use the
`rsconnect content search` subcommand to find content on Posit Connect.
By default, the `rsconnect content search` command will return metadata for ALL
of the content on a Posit Connect server, both published and unpublished content.

> **Note**
> When using the `--r-version` and `--py-version` flags, users should
> make sure to quote the arguments to avoid conflicting with your shell. For
> example, bash would interpret `--py-version >3.0.0` as a shell redirect because of the
> unquoted `>` character.

```bash
# return only published content
rsconnect content search --published

# return only unpublished content
rsconnect content search --unpublished

# return published content where the python version is at least 3.9.0
rsconnect content search --published --py-version ">=3.9.0"

# return published content where the R version is exactly 3.6.3
rsconnect content search --published --r-version "==3.6.3"

# return published content where the content type is a static RMD
rsconnect content search --content-type rmd-static

# return published content where the content type is either shiny OR fast-api
rsconnect content search --content-type shiny --content-type python-fastapi

# return all content, published or unpublished, where the title contains the
# text "Stock Report"
rsconnect content search --title-contains "Stock Report"

# return published content, results are ordered by when the content was last
# deployed
rsconnect content search --published --order-by last_deployed

# return published content, results are ordered by when the content was
# created
rsconnect content search --published --order-by created
```

### Finding r and python versions

One common use for the `search` command might be to find the versions of
r and python that are currently in use on your Posit Connect server before a migration.

```bash
# search for all published content and print the unique r and python version
# combinations
rsconnect content search --published | jq -c '.[] | {py_version,r_version}' | sort |
uniq
# {"py_version":"3.8.2","r_version":"3.5.3"}
# {"py_version":"3.8.2","r_version":"3.6.3"}
# {"py_version":"3.8.2","r_version":null}
# {"py_version":null,"r_version":"3.5.3"}
# {"py_version":null,"r_version":"3.6.3"}
# {"py_version":null,"r_version":null}
```

### Finding recently deployed content

```bash
# return only the 10 most recently deployed content items
rsconnect content search \
    --order-by last_deployed \
    --published | jq -c 'limit(10; .[]) | { guid, last_deployed_time }'
# {"guid":"4ffc819c-065c-420c-88eb-332db1133317","last_deployed_time":"2021-12-02T18:09:11Z"}
# {"guid":"aa2603f8-1988-484f-a335-193f2c57e6c4","last_deployed_time":"2021-12-01T20:56:07Z"}
# {"guid":"051252f0-4f70-438f-9be1-d818a3b5f8d9","last_deployed_time":"2021-12-01T20:37:01Z"}
# {"guid":"015143da-b75f-407c-81b1-99c4a724341e","last_deployed_time":"2021-11-30T16:56:21Z"}
# {"guid":"bcc74209-3a81-4b9c-acd5-d24a597c256c","last_deployed_time":"2021-11-30T15:51:07Z"}
# {"guid":"f21d7767-c99e-4dd4-9b00-ff8ec9ae2f53","last_deployed_time":"2021-11-23T18:46:28Z"}
# {"guid":"da4f709c-c383-4fbc-89e2-f032b2d7e91d","last_deployed_time":"2021-11-23T18:46:28Z"}
# {"guid":"9180809d-38fd-4730-a0e0-8568c45d87b7","last_deployed_time":"2021-11-23T15:16:19Z"}
# {"guid":"2b1d2ab8-927d-4956-bbf9-29798d039bc5","last_deployed_time":"2021-11-22T18:33:17Z"}
# {"guid":"c96db3f3-87a1-4df5-9f58-eb109c397718","last_deployed_time":"2021-11-19T20:25:33Z"}
```

### Add to build from search results

One common use case might be to `rsconnect content build add` content for build
based on the results of a `rsconnect content search`. For example:

```bash
# search for all API type content, then
# for each guid, add it to the "tracked" content items
for guid in $(rsconnect content search \
        --published \
        --content-type python-api \
        --content-type api | jq -r '.[].guid'); do
    rsconnect content build add --guid $guid
done
```

Adding content items one at a time can be a slow operation. This is because
`rsconnect content build add` must fetch metadata for each content item before it
is added to the "tracked" content items. By providing multiple `--guid` arguments
to the `rsconnect content build add` subcommand, we can fetch metadata for multiple content items
in a single api call, which speeds up the operation significantly.

```bash
# write the guid of every published content item to a file called guids.txt
rsconnect content search --published | jq '.[].guid' > guids.txt

# bulk-add from the guids.txt with a single `rsconnect content build add` command
xargs printf -- '-g %s\n' < guids.txt | xargs rsconnect content build add
```
## Programmatic Provisioning

Posit Connect supports the programmatic bootstrapping of an administrator API key
for scripted provisioning tasks. This process is supported by the `rsconnect bootstrap` command,
which uses a JSON Web Token to request an initial API key from a fresh Connect instance.

```bash
rsconnect bootstrap \
    --server https://connect.example.org:3939 \
    --jwt-keypath /path/to/secret.key
```

A full description on how to use `rsconnect bootstrap` in a provisioning workflow is provided in the Connect administrator guide's
[programmatic provisioning](https://docs.posit.co/connect/admin/programmatic-provisioning) documentation.

## Server Administration Tasks

Starting with the 2023.05 edition of Posit Connect, `rsconnect-python` can be
used to perform certain server administration tasks, such as instance managing
runtime caches. For more information on runtime caches in Posit Connect, see the
Connect Admin Guide's section on [runtime
caches](https://docs.posit.co/connect/admin/server-management/runtime-caches/).

Examples in this section will use `--name myserver` to stand in for your Connect
server information. See [Managing Server
Information](#managing-server-information) above for more details.

### Enumerate Runtime Caches
*New in Connect 2023.05*

Use the command below to enumerate runtime caches on a Connect server. The
command will output a JSON object containing a list of runtime caches . Each
cache entry will contain the following information:

- `language`: The language of content that uses the cache, either R or Python.
- `version`: The language version of the content that uses the cache.
- `image_name`: The execution environment of the cache. The string `Local`
  denotes native execution. For Connect instances that use off-host execution,
  the name of the image that uses the cache will be displayed.

```bash
rsconnect system caches list --name myserver
# {
#   "caches": [
#     {
#       "language": "R",
#       "version": "3.6.3",
#       "image_name": "Local"
#     },
#     {
#       "language": "Python",
#       "version": "3.9.5",
#       "image_name": "Local"
#     },
#         {
#       "language": "R",
#       "version": "3.6.3",
#       "image_name": "rstudio/content-base:r3.6.3-py3.9.5-bionic"
#     },
#     {
#       "language": "Python",
#       "version": "3.9.5",
#       "image_name": "rstudio/content-base:r3.6.3-py3.9.5-bionic"
#     }
#   ]
# }
```

> **Note**
> The `image_name` field returned by the server will use sanitized versions
> of names.

### Delete Runtime Caches
*New in Connect 2023.05*

When Connect's execution environment changes, runtime caches may be invalidated.
In these cases, you will need to delete the affected runtime caches using the
`system caches delete` command.

> **Warning**
> After deleting a cache, the first time affected content is visited, Connect
> will need to reconstruct its environment. This can take a long time. To
> mitigate this, you can use the [`content build`](#content-build) command to
> rebuild affected content ahead of time. You may want to do this just for
> high-priority content, or for all content.

To delete a runtime cache, call the `system caches delete` command, specifying a
Connect server, as well as the language (`-l, --language`), version (`-V,
--version`), and image name (`-I, --image-name`) for the cache you wish to
delete. Deleting a large cache might take a while. The command will wait for
Connect to finish the task.

Use the following parameters specify the target cache:

- `language` (required) must name `R` or `Python`. It is case-insensitive.
- `version` (required) must be a three-part version number, e.g. `3.8.12`.
- `image-name` (optional) defaults to `Local`, which targets caches used for
  natively-executed content. Off-host images can be specified using either the
  literal image name or the sanitized name returned by the `list` command.

Use the dry run flag (`-d, --dry-run`) to surface any errors ahead of
deletion.

```bash
rsconnect system caches delete \
    --name myserver \
    --language Python \
    --version 3.9.5 \
    --image-name rstudio/content-base:r3.6.3-py3.9.5-bionic \
    --dry-run
# Dry run finished

rsconnect system caches delete \
    --name myserver \
    --language Python \
    --version 3.9.5 \
    --image-name rstudio/content-base:r3.6.3-py3.9.5-bionic
# Deleting runtime cache...
# Successfully deleted runtime cache
```

You should run these commands for each cache you wish to delete.
