Skip to main content

pyfortiaigate

Python client for the FortiAIGate 8.x management API and its OpenAI-compatible gateway. Standard library only: no dependencies, and the client is one self-contained module you can copy onto a host that cannot pip install.

pip install pyfortiaigate
from pyfortiaigate import FortiAIGate, regex_detector_body

with FortiAIGate("https://faig.example.com", "admin", "<password>") as faig:
    # Everything by name; ensure_* creates, updates or leaves alone, and approves.
    faig.ensure_detector(
        "team-a", regex_detector_body("no-ssn", [("ssn", r"\d{3}-\d{2}-\d{4}", "block")])
    )
    faig.ensure_guardrail("team-a", "pii", ["no-ssn"])
    faig.ensure_policy("team-a", "pii-policy", ["pii"], ["pii"], provider_ids=["openai"])

From the shell (pip install "pyfortiaigate[cli]" adds colour, panels and bar charts; without it the output is plain text):

pyfortiaigate dashboard --ws team-a
pyfortiaigate cost --days 1 --by key
pyfortiaigate logs --key student04-key --verdict Block --follow

pyfortiaigate dashboard

What it handles for you

  • Auth: session login (logs in on first call, again when the session expires) or a bearer token; a fresh CSRF token for every mutation.
  • Flaky networks: transport failures are retried with backoff. A request that was never answered is retried for every method; a connection dropped after the request went out is retried only for GET, so a mutation is never sent twice.
  • One connection: requests reuse a keep-alive HTTPS connection, which matters through tunnels where every new connect costs seconds.
  • Names, not ids: workspaces, detectors, guardrails, policies and keys can be given by name anywhere, and ensure_* makes setup scripts safe to re-run.
  • Typed errors: NotFound, ModelNotAvailable, Conflict, RateLimited, ... all subclasses of FaigError; optional waiting on 429s.
  • Undocumented behaviour: body builders encode what the API silently requires (a regex detector's flat rules list, DLP disposition, at least one detector per guardrail).

Coverage

Users and invitations, workspaces, detectors (custom and built-in), guardrails (including scan tests), policies, the approval workflow, virtual keys (create, update, rotate, revoke), usage and cost reports, guardrail analytics, traffic and ICAP logs, the detector Playground, Natural Language detectors, AI providers, models and what a key may call, DLP labels, audit logs, and the gateway (check_key, available_models, chat_completion, streaming), plus a pyfortiaigate command line.

Full reference: https://ftnt-dspille.github.io/pyfortiaigate/

TLS

Verification is on by default. For an appliance with a self-signed certificate, pass its CA: FortiAIGate(url, user, pw, verify="/path/ca.pem"). verify=False turns checking off and is for isolated labs only.

Development

uv venv && uv pip install -e ".[dev]"
.venv/bin/pytest                 # offline suite, coverage enforced
.venv/bin/ruff format --check . && .venv/bin/ruff check .
.venv/bin/mypy src               # strict
.venv/bin/mkdocs serve           # docs at http://127.0.0.1:8000

Live tests are opt-in and read-only. Fill in .env (gitignored; copied from .env.example), set FAIG_LIVE=1, then:

.venv/bin/pytest tests/live -v

Unofficial; not affiliated with or supported by Fortinet. MIT licensed.

Metadata

Release files for pyfortiaigate 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfortiaigate 0.4.0
File Size Uploaded Provenance
pyfortiaigate-0.4.0.tar.gz 177.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyfortiaigate 0.4.0
File Interpreter ABI Platform
pyfortiaigate-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 247.2 kB

Release files / pyfortiaigate-0.4.0.tar.gz

Download URL pyfortiaigate-0.4.0.tar.gz
Size 177.4 kB
Tags Source
SHA-256 checksum
How to use checksums
30f3510215cde97dc5bb5bb046d65acc31c5d392a37597c2604b54c8d6017087
BLAKE2b-256 checksum
How to use checksums
4e8c5bc9445797ddb209f46623d3cd1c3c1ae78fafef3c3794f3d90ec0c15874
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / pyfortiaigate-0.4.0-py3-none-any.whl

Download URL pyfortiaigate-0.4.0-py3-none-any.whl
Size 69.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89240606c44f35562177c05840a81f63672353a3f7f32c721787507d34a0347a
BLAKE2b-256 checksum
How to use checksums
b2baa3fa392b0c3ed8980c0a3c36fe02123afc04318f54c2b0d11a2a58d8f443
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Security for pyfortiaigate 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyfortiaigate-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page