# Scanning a Build

In order to collect coverage information SeaLights agents need to first scan the Python script files for the build information.

{% hint style="info" %}
See '[Generating an Agent token](https://docs.sealights.io/knowledgebase/settings/token-access-and-management#token-list-and-token-creation-2)' for instructions on how to generate a token.
{% endhint %}

## Scanning a build <a href="#scanning-a-build" id="scanning-a-build"></a>

Scanning a build in Python is done using the Python agent with the `scan` flag:

{% code overflow="wrap" lineNumbers="true" %}

```
sl-python scan
```

{% endcode %}

you can also use the command with explicit parameters

{% code overflow="wrap" lineNumbers="true" %}

```
sl-python scan --tokenfile ./sltoken.txt --buildsessionidfile ./path-to/buildSessionId.txt --scm none
```

{% endcode %}

{% hint style="info" %}
See [Command Reference](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/python-agent/command-reference.md#scanning-a-build) for command details.
{% endhint %}

## Using `.slignore` to Exclude Files or Directories

Use a `.slignore` file to exclude specific Python files or directories from being scanned.\
It works like a **`.gitignore`**, giving you finer control than CLI‑only exclusions.

Create a `.slignore` file in the **project root**:

```
# Comments start with #

# Exclude virtual environments
**/venv/**
**/.venv/**

# Exclude test folders (default behavior also excludes "*tests*")
**/tests/**

# Exclude Python caches
**/__pycache__/**
**/*.pyc

# Exclude generated or vendored code
**/generated/**
**/site-packages/**

# Exclude specific legacy files
legacy/old_script.py
```

### Pattern Syntax

`.slignore` follows **`.gitignore` rules** (same as other SeaLights agents): [\[docs.sealights.io\]](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/ignoring-files-or-folders), [\[docs.sealights.io\]](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/ignoring-files-or-folders.md)

* `**` matches any directory depth
* `*` matches any characters within a directory
* Lines starting with `#` are comments
* Empty lines are ignored
* Prefix `!` to *include* something inside an excluded area

### Merge & Precedence (Simple Rules)

CLI always wins and `.slignore` is applied for **every scan operation** (test/run)

1. **CLI parameters** (`--exclude`, `--include`)
2. **.slignore file**
3. **Python agent defaults**

{% hint style="info" %}

#### Tips

* Start with minimal patterns and add more as needed.
* Inspect what’s being scanned by running the scan with high‑verbosity logs.
* Use `.slignore` for file‑level control when CLI excludes are too coarse.
  {% endhint %}


---

# 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.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/python-agent/scanning-a-build.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.
