Skip to main content

Python SDK for the LinkShieldAI URL safety API.

Project description

LinkShieldAI Python SDK

Python wrapper for the LinkShieldAI API at https://api.linkshieldai.com.

The SDK supports:

  • Basic URL safety checks
  • Detailed checks with screenshot URL and detected tag
  • Screenshot download
  • NSFW site checks
  • Chimera AI classification
  • Sync and async clients
  • Retry/backoff for transient API failures
  • A small command-line tool

Install

From this folder:

python -m pip install -e .

For tests:

python -m pip install -e ".[dev]"
python -m pytest

Authentication

The API uses a query parameter named key.

Pass the API key directly:

from linkshieldai import LinkShieldAI

client = LinkShieldAI(api_key="YOUR_API_KEY")

Or set an environment variable:

$env:LINKSHIELDAI_API_KEY = "YOUR_API_KEY"
from linkshieldai import LinkShieldAI

client = LinkShieldAI()

Basic Check

Wraps:

GET https://api.linkshieldai.com/?key={key}&url={url}
from linkshieldai import LinkShieldAI

client = LinkShieldAI(api_key="YOUR_API_KEY")
result = client.basic_check("https://example.com")

print(result.result)
print(result.is_malicious)
print(result.raw)

Detailed Check

Wraps:

GET https://api.linkshieldai.com/classify_link?key={key}&url={url}
result = client.detailed_check("https://example.com")

print(result.result)
print(result.screenshot_url)
print(result.tag)

The API field "screenshot url" is normalized to screenshot_url.

Download Screenshot

Wraps:

GET https://api.linkshieldai.com/screenshot/{file_name}
image_bytes = client.get_screenshot("05046f.png")
client.get_screenshot("https://api.linkshieldai.com/screenshot/05046f.png", "site.png")

NSFW Check

Wraps:

GET https://api.linkshieldai.com/nsfw/site?key={key}&url={url}
result = client.nsfw_check("https://example.com")
print(result.is_nsfw)

Chimera Check

Wraps:

GET https://api.linkshieldai.com/chimera?key={key}&url={url}
result = client.chimera("https://google.com")

print(result.result)
print(result.probability)
print(result.detection_method)
print(result.matched_signatures)

Async Usage

import asyncio
from linkshieldai import AsyncLinkShieldAI


async def main():
    async with AsyncLinkShieldAI(api_key="YOUR_API_KEY") as client:
        result = await client.chimera("https://google.com")
        print(result.result, result.probability)


asyncio.run(main())

Custom API Host

The default host is:

https://api.linkshieldai.com

You can override it for staging or testing:

client = LinkShieldAI(base_url="https://api.linkshieldai.com")

Timeouts, Retries, and Logging

By default the SDK uses:

  • timeout=10.0
  • max_retries=2
  • backoff_factor=0.5

Retries are applied to temporary connection failures and HTTP 429, 502, 503, and 504.

import logging
from linkshieldai import LinkShieldAI

logging.basicConfig(level=logging.DEBUG)

client = LinkShieldAI(
    timeout=15.0,
    max_retries=3,
    backoff_factor=1.0,
)

CLI

After installation, use:

linkshieldai --api-key YOUR_API_KEY basic https://example.com
linkshieldai --api-key YOUR_API_KEY detailed https://example.com
linkshieldai --api-key YOUR_API_KEY nsfw https://example.com
linkshieldai --api-key YOUR_API_KEY chimera https://google.com
linkshieldai --api-key YOUR_API_KEY screenshot 05046f.png --output site.png

You can omit --api-key if LINKSHIELDAI_API_KEY is set.

Errors

from linkshieldai import (
    APIConnectionError,
    APIResponseError,
    APIStatusError,
    AuthenticationError,
    RateLimitError,
)
  • AuthenticationError: missing API key.
  • RateLimitError: HTTP 429.
  • APIStatusError: non-success HTTP status.
  • APIResponseError: malformed JSON or API payload with Error / error.
  • APIConnectionError: timeout, DNS, or connection failure.

Raw API payloads are preserved on result objects through .raw.

Production Notes

  • Keep API keys server-side. Do not expose them in browser JavaScript.
  • Use max_retries with a small non-zero value for bots, moderation pipelines, and web apps.
  • Catch RateLimitError when running near the documented limits.
  • Tests are mocked by default and do not call the live API.
  • For live smoke tests, set LINKSHIELDAI_API_KEY and run python -m pytest tests/test_live_optional.py.

Project details


Download files

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

Source Distribution

linkshieldai-0.2.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

linkshieldai-0.2.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file linkshieldai-0.2.1.tar.gz.

File metadata

  • Download URL: linkshieldai-0.2.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for linkshieldai-0.2.1.tar.gz
Algorithm Hash digest
SHA256 92e0e1c7e76d203c15ba7d21763e58449010d226ed4836e55e662f82f77ac114
MD5 b5c46dd8b1b4e3162081ac6ae26d7ae7
BLAKE2b-256 419c4a30158e2c3404a744852245c93dfd7d1e5e88d933d1a89dd4c4ae087b65

See more details on using hashes here.

File details

Details for the file linkshieldai-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: linkshieldai-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for linkshieldai-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9fb1637c7bd8a19be62f079fc11e1bf3b4cba2ddb5807f9e4a4e0be12c5ab541
MD5 7bb92816c3955438d1c306d3c8c430a8
BLAKE2b-256 b566ad49daa4860d62899f09ae70721c88d68a6e8fc19a8140b3df92464373dc

See more details on using hashes here.

Supported by

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