Skip to main content

Guard Logo
Guard Local Detector

A local detection engine for the Guard Python client, integrating visual safety filters into your applications

License: AGPL v3 PRs Welcome

Features

🛡️ Multi-Layered Content Moderation: Automatically detects AI-generated, violent, and explicit content in images and videos.

⚡ Fast Local Inference: Runs a lightweight computer vision model entirely on-device using ONNX Runtime. It operates with zero network latency and completely avoids pulling in massive deep-learning dependencies like PyTorch.

🏢 Seamless Production Testing: Designed to perfectly mirror the cloud API's data structures. This allows enterprise teams to easily build and test their integration logic locally before routing production traffic to the cloud API.

🧑‍💻 Instant Open-Source Baseline: Provides open-source developers and hobbyists with a free, immediately usable baseline classifier. Get a foundational media safety layer up and running in minutes, not days.

Installation

Recommended Way

We highly recommend using this package as an optional extension of the main Guard client. This provides a single, unified API for both cloud and local detection.

pip install guard-client[local]

Standalone Way

pip install guard-local-detector

Quick Start

Using the Unified Client (Recommended)

If you installed via guard-client[local], you do not need to import this package directly. Ask the client for the local engine and it routes every call here — no API key, and no network access.

from guard_client import GuardClient

with GuardClient(engine="local") as client:
    result = client.analyze("/local/paths/to/video.mp4")

    for item in result.results:
        print(f"{item.label}: {item.score}")  # AI-Generated: 71

The results carry the same labels, task ids, and 0-100 scores a cloud run returns, so the same code works against either engine. A cloud-configured client can also send a single call locally with client.analyze(source, engine="local").

Using the Standalone Engine

The engine works on bytes and a MIME type, never a path — reading the source is the caller's job.

import guard_local

engine = guard_local.LocalDetectorEngine()

with open("/local/paths/to/image.png", "rb") as handle:
    results = engine.analyze(handle.read(), "image/png")
    
for item in results:
    print(f"{item['label']}: {item['score']:.2f}")

# AI-Generated: 0.90
# Violence: 0.02
# Explicit: 0.01

Development

This project uses uv for lightning-fast Python package and environment management.

Prerequisites

  • uv (already installed on your system)

Setup

  1. Clone the repository:

    git clone https://github.com/elhio/guard-local-python.git
    cd guard-local-python
    
  2. Sync the environment:

    uv sync
    

    This command automatically creates a .venv virtual environment, reads the uv.lock file, and installs all core and development dependencies exactly as they were locked.

  3. Run tests:

    uv run pytest
    
  4. Formatting, linting, and type checking:

    uv run ruff format
    uv run ruff check
    uv run mypy
    
  5. Build for production:

    uv build
    

Contributing

We welcome contributions! Please note that all contributors must sign our automated CLA. Read more in our Contributing Guide.

License

This repository and its corresponding PyPI package are licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) - see the LICENSE file for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

guard_local_detector-0.0.1.tar.gz (7.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

guard_local_detector-0.0.1-py3-none-any.whl (7.3 MB view details)

Uploaded Python 3

File details

Details for the file guard_local_detector-0.0.1.tar.gz.

File metadata

  • Download URL: guard_local_detector-0.0.1.tar.gz
  • Upload date:
  • Size: 7.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for guard_local_detector-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c0b9a84f6f3b76df743feef5db3b0df02aafe3cdf1edacd08168563467f592e6
MD5 1800c04203e3becaed6c2f2e37cb8761
BLAKE2b-256 8438daaef254940af0df2c2accbd105e42b5cf5b0589a70fc0b1033f1052376a

See more details on using hashes here.

Provenance

The following attestation bundles were made for guard_local_detector-0.0.1.tar.gz:

Publisher: release.yml on elhio/guard-local-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file guard_local_detector-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for guard_local_detector-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d71c8031c79153c37ee211cc111b04cf379b277f29a0108d280e66627c87d905
MD5 d3eb7fa046d86b3d5bf7cd393d027b8e
BLAKE2b-256 08fe20308da79e835ba339f1ae2c92aef04d4eb9c26de17faca2b829d17182cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for guard_local_detector-0.0.1-py3-none-any.whl:

Publisher: release.yml on elhio/guard-local-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page