# 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 [#scanning-a-build](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/command-reference#scanning-a-build "mention") 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 %}
