# Python

### Sample

An example Python project configured with BugSplat exception reporting can be found [here](https://github.com/BugSplat-Git/my-python-crasher).

### Installation

BugSplat recommends you use [bugsplat-py](https://github.com/BugSplat-Git/bugsplat-py) with a Python [virtual environment](https://docs.python.org/3/library/venv.html). To create a virtual environment for your project please run the following command at your project's root directory:

```shell
python -m venv venv
```

Activate your virtual environment by running the following command:

```shell
# unix/macos
source venv/bin/activate

# windows
.\env\Scripts\activate
```

Install the [bugsplat](https://pypi.org/project/bugsplat) package using pip:

```bash
pip install bugsplat
```

### Usage

Import the BugSplat class

```python
from bugsplat import BugSplat
```

Create a new BugSplat instance passing it the name of your BugSplat database, application, and version

```python
bugsplat = BugSplat(database, application, version)
```

Optionally, you set default values for key, description, email, user, and additionaFilePaths

```python
bugsplat.set_default_app_key('key!')
bugsplat.set_default_description('description!')
bugsplat.set_default_email('fred@bugsplat.com')
bugsplat.set_default_user('Fred')
bugsplat.set_default_additional_file_paths([
    './path/to/additional-file.txt',
    './path/to/additional-file-2.txt'
])
```

Wrap your application code in a try/except block. In the except block call post. You can override any of the default properties that were set in step 3

```python
try:
    crash()
except Exception as e:
    bugsplat.post(
        e,
        additional_file_paths=[],
        app_key='other key!',
        description='other description!',
        email='barney@bugsplat.com',
        user='Barney'
    )
```

Once you've posted a crash, navigate to the Crashes page and click the link in the ID column to see the crash's details

![](/files/BCvdjP8bHKnPZplQmsxR)

### User Feedback

In addition to crash reporting, BugSplat supports collecting non-crashing user feedback such as bug reports and feature requests. Feedback reports appear in BugSplat with the "User Feedback" type, grouped by title.

```python
bugsplat.post_feedback(
    'Login button broken',
    description='Nothing happens when I tap it',
    email='jane@example.com',
    user='Jane',
    app_key='en-US'
)
```

To include file attachments such as screenshots or log files:

```python
bugsplat.post_feedback(
    'Login button broken',
    description='Nothing happens when I tap it',
    email='jane@example.com',
    user='Jane',
    additional_file_paths=[
        './path/to/screenshot.png',
        './path/to/log.txt'
    ]
)
```

Thanks for using BugSplat ❤️


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bugsplat.com/introduction/getting-started/integrations/cross-platform/python.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
