> For the complete documentation index, see [llms.txt](https://vigil.deadbits.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vigil.deadbits.ai/overview/use-vigil/python-library.md).

# Python library

Vigil can also be used within your own Python application as a library. This allows you to access the input and output scanners, canary token, and vector database functionality.

**The Vigil library must be installed via**

```
pip install -e .
```

**Then import the `Vigil` class and pass it your config file.**

## Initialize scanners

```python
from vigil.vigil import Vigil

app = Vigil.from_config('conf/openai.conf')
```

Pass your configuration file to `Vigil.from_config.` This exposes the following functions:

* `input_scanner.perform_scan(prompt)`
* `output_scanner.perform_scan(prompt, response)`
* `canary_tokens.add`
* `canary_tokens.check`
* `vectordb.add_texts`
* `vectordb.add_embeddings`
* `embedder.generate`

## Scan Prompts and Responses

<pre class="language-python"><code class="lang-python">app.input_scanner.perform_scan(
    input_prompt="prompt goes here"
)
<strong>
</strong>app.output_scanner.perform_scan(
    input_prompt="prompt goes here",
    input_resp="LLM response goes here"
)
</code></pre>

The scanners return a Python dictionary with the full results and any metadata.

## Canary Tokens

```python
updated_prompt = app.canary_tokens.add(
    prompt=application_prompt,          # prompt to add canary token to
    always=always if always else False, # add suffix to always include canary
    length=length if length else 16,    # canary token length
    header=header if header else '<-@!-- {canary} --@!->', # customize canary header
)

# canary_tokens.check() returns True if a canary is found
result = app.canary_tokens.check(prompt=llm_response)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://vigil.deadbits.ai/overview/use-vigil/python-library.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
