### Scan PDQ Hashes Example (Async) Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Example demonstrating how to use the asynchronous scan_pdq_hashes method. Requires importing asyncio and ArachnidShieldAsync. ```python import asyncio from arachnid_shield_sdk import ArachnidShieldAsync, ScanMediaFromPdq async def scan_hashes(): shield = ArachnidShieldAsync(username="user", password="pass") config = ScanMediaFromPdq(hashes=["hash1", "hash2"]) result = await shield.scan_pdq_hashes(config) return result asyncio.run(scan_hashes()) ``` -------------------------------- ### Install Arachnid Shield SDK Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/README.md Install the SDK using pip. This command should be run in your terminal. ```sh pip install arachnid-shield-sdk ``` -------------------------------- ### Synchronous Client Setup Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/usage-patterns.md Instantiate the synchronous ArachnidShield client with your username and password. ```python from arachnid_shield_sdk import ArachnidShield shield = ArachnidShield(username="your_username", password="your_password") ``` -------------------------------- ### Example Usage of ScanMediaFromPdq Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/types.md Demonstrates how to create a ScanMediaFromPdq configuration object and use it to scan PDQ hashes with the shield SDK. ```python from arachnid_shield_sdk import ScanMediaFromPdq config = ScanMediaFromPdq(hashes=["base64_hash_1", "base64_hash_2"]) result = shield.scan_pdq_hashes(config) ``` -------------------------------- ### Instantiate VisualMatchDetails Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/types.md Example of how to instantiate the VisualMatchDetails dataclass. This is typically accessed through ScannedMedia objects. ```python # VisualMatchDetails is typically accessed through ScannedMedia visual_details = VisualMatchDetails( timestamp=10.5, matches=[ MatchDetails( sha1_base32="ABC...", sha256_hex="123...", distance=1300, classification=MediaClassification.CSAM ) ] ) ``` -------------------------------- ### Direct HTTP Request Example for POST /v1/url/ Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/endpoints.md This example demonstrates how to scan media from a URL using a direct HTTP POST request with curl. Ensure you replace 'username:password' with your actual credentials and 'https://example.com/image.jpeg' with the target URL. ```bash curl -X POST https://shield.projectarachnid.com/v1/url/ \ -H "Authorization: Basic $(echo -n 'username:password' | base64)" \ -H "Content-Type: application/json" \ -d '{"url":"https://example.com/image.jpeg"}' ``` -------------------------------- ### Asynchronous Client Setup Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/usage-patterns.md Instantiate the asynchronous ArachnidShieldAsync client within an asyncio event loop. ```python import asyncio from arachnid_shield_sdk import ArachnidShieldAsync async def main(): shield = ArachnidShieldAsync(username="your_username", password="your_password") # Use shield... asyncio.run(main()) ``` -------------------------------- ### SDK Media Scan Integration Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/endpoints.md Example demonstrating how to use the ArachnidShield SDK to scan media from bytes, including reading file contents and specifying the content type. ```python from arachnid_shield_sdk import ArachnidShield shield = ArachnidShield(username="user", password="pass") with open("image.jpeg", "rb") as f: contents = f.read() scanned = shield.scan_media_from_bytes(contents, "image/jpeg") ``` -------------------------------- ### Framework Integration: Flask Example Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/MANIFEST.txt Integrate the Arachnid Shield SDK into a Flask web application for scanning media uploaded via HTTP requests. ```python from flask import Flask, request, jsonify from arachnid_shield.client import ArachnidShield app = Flask(__name__) client = ArachnidShield(api_key="YOUR_API_KEY") @app.route('/upload', methods=['POST']) def upload_file(): if 'file' not in request.files: return jsonify({'error': 'No file part'}), 400 file = request.files['file'] if file.filename == '': return jsonify({'error': 'No selected file'}), 400 try: # Read file content as bytes media_bytes = file.read() result = client.scan_media_from_bytes(media_bytes) return jsonify(result.model_dump()) except Exception as e: return jsonify({'error': str(e)}), 500 if __name__ == '__main__': app.run(debug=True) ``` -------------------------------- ### Python SDK Integration for POST /v1/url/ Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/endpoints.md This example shows how to use the ArachnidShield SDK to scan media from a URL. Initialize the client with your username and password, then call the `scan_media_from_url` method with the URL to scan. ```python from arachnid_shield_sdk import ArachnidShield shield = ArachnidShield(username="user", password="pass") scanned = shield.scan_media_from_url("https://example.com/image.jpeg") ``` -------------------------------- ### Framework Integration: FastAPI Example Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/MANIFEST.txt Integrate the Arachnid Shield SDK into a FastAPI web application for scanning media uploaded via HTTP requests. ```python from fastapi import FastAPI, File, UploadFile, HTTPException from arachnid_shield.client import ArachnidShieldAsync import asyncio app = FastAPI() client = ArachnidShieldAsync(api_key="YOUR_API_KEY") @app.post('/upload') async def upload_file(file: UploadFile = File(...)): try: media_bytes = await file.read() result = await client.scan_media_from_bytes(media_bytes) return result.model_dump() except Exception as e: raise HTTPException(status_code=500, detail=str(e)) if __name__ == '__main__': import uvicorn uvicorn.run(app, host='0.0.0.0', port=8000) ``` -------------------------------- ### Example Trigger: Hostname Authorization Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/errors.md This example shows how an ArachnidShieldException is raised when the authenticated user is not authorized to use the requesting hostname. ```python shield = ArachnidShield(username="user", password="pass") try: # Scanning from a URL on an unauthorized domain scanned = shield.scan_media_from_url("https://unauthorized-domain.com/image.jpeg") except ArachnidShieldException as e: print(f"Hostname error: {e}") ``` -------------------------------- ### Example Trigger: Authentication Failure Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/errors.md This example demonstrates how an ArachnidShieldException is raised for authentication failures due to invalid or missing API credentials. ```python unauthorized_shield = ArachnidShield(username="invalid", password="invalid") try: scanned = unauthorized_shield.scan_media_from_file(filepath) except ArachnidShieldException as e: print(f"Auth failed: {e}") ``` -------------------------------- ### Concurrent Media Scans Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/configuration.md This example shows how to perform multiple media scan operations concurrently using `asyncio.gather`. This is useful for improving performance when scanning several files. Ensure all necessary contents and mime types are provided. ```python import asyncio from arachnid_shield_sdk import ArachnidShieldAsync async def scan_multiple(): shield = ArachnidShieldAsync(username="user", password="pass") # Scan three files concurrently results = await asyncio.gather( shield.scan_media_from_bytes(contents1, "image/jpeg"), shield.scan_media_from_bytes(contents2, "image/png"), shield.scan_media_from_bytes(contents3, "image/gif") ) return results results = asyncio.run(scan_multiple()) ``` -------------------------------- ### Process PDQ Match Details Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/models.md Example of how to access and display details about a PDQ hash match. It checks if the match is against known media and prints the classification and near-match SHA256 hash if available. ```python config = ScanMediaFromPdq(hashes=["hash1"]) result = shield.scan_pdq_hashes(config) for pdq_hash, pdq_match in result.scanned_hashes.items(): if pdq_match.matches_known_media: print(f"Classification: {pdq_match.classification}") if pdq_match.near_match_details: print(f" SHA256: {pdq_match.near_match_details.sha256_hex}") ``` -------------------------------- ### Synchronous Media Scanning with Arachnid Shield SDK Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/README.md Use the ArachnidShield client for synchronous media scanning. Instantiate the client with your username and password. This example shows how to scan image bytes and check for known harmful media. ```python from arachnid_shield_sdk import ArachnidShield shield = ArachnidShield(username="", password="") def process_media(contents): scanned_media = shield.scan_media_from_bytes(contents, "image/jpeg") if scanned_media.matches_known_image: print(f"harmful media found!: {scanned_media}") ... def main(): with open("some-image.jpeg", "rb") as f: contents = f.read() process_media_for_user(contents) if __name__ == '__main__': main() ``` -------------------------------- ### Direct HTTP Media Scan Request Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/endpoints.md Example using curl to send a POST request to the /v1/media/ endpoint with Basic Authentication and raw media data. ```bash curl -X POST https://shield.projectarachnid.com/v1/media/ \ -H "Authorization: Basic $(echo -n 'username:password' | base64)" \ -H "Content-Type: image/jpeg" \ --data-binary "@image.jpeg" ``` -------------------------------- ### FastAPI Integration for Async Media Scanning Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/usage-patterns.md Implement asynchronous media scanning in a FastAPI application using the Arachnid Shield SDK. This example demonstrates handling file uploads and asynchronous operations. ```python import io from fastapi import FastAPI, UploadFile, File, HTTPException from arachnid_shield_sdk import ArachnidShieldAsync, ArachnidShieldException app = FastAPI() shield = ArachnidShieldAsync(username="user", password="pass") @app.post("/scan") async def scan_upload(file: UploadFile = File(...)): try: contents = await file.read() mime_type = file.content_type scanned = await shield.scan_media_from_bytes(contents, mime_type) return { "sha256": scanned.sha256_hex, "classification": scanned.classification, "matches_known_media": scanned.matches_known_media } except ArachnidShieldException as e: raise HTTPException(status_code=400, detail=str(e)) except Exception as e: raise HTTPException(status_code=500, detail="Scan failed") ``` -------------------------------- ### Handle Authentication Error (401) Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/exceptions.md Provides an example of catching an `ArachnidShieldException` and specifically checking if it's an authentication error based on the error message. Use this to guide users on credential issues. ```python try: # Using invalid credentials shield = ArachnidShield(username="invalid", password="invalid") scanned = shield.scan_media_from_bytes(contents, "image/jpeg") except ArachnidShieldException as e: if "Authorization" in str(e): print("Invalid credentials provided") print(f"Details: {e.detail.detail}") ``` -------------------------------- ### Initialize Client Using Environment Variable for Base URL Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/configuration.md Create an ArachnidShield instance. If ARACHNID_SHIELD_URL is set, it will be used as the base URL; otherwise, the default will be used. ```python from arachnid_shield_sdk import ArachnidShield # Will use https://custom-shield-api.example.com/ from environment shield = ArachnidShield(username="user", password="pass") ``` -------------------------------- ### Import Main Client Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/README.md Import the necessary ArachnidShield and ArachnidShieldAsync classes from the SDK. ```python from arachnid_shield_sdk import ArachnidShield, ArachnidShieldAsync ``` -------------------------------- ### Get String Representation of ArachnidShieldException Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/exceptions.md Illustrates how to get the human-readable error message directly from an `ArachnidShieldException` instance using `str()`. This is convenient for quick error display. ```python try: scanned = shield.scan_media_from_bytes(contents, mime_type) except ArachnidShieldException as e: print(str(e)) # Prints the error message directly # Output: "Please supply your API username and password in the Authorization header" ``` -------------------------------- ### Synchronous Client Initialization Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/MANIFEST.txt Initialize the synchronous ArachnidShield client. Configure with base URL, timeout, and authentication. ```python from arachnid_shield.client import ArachnidShield client = ArachnidShield( base_url="https://api.example.com", timeout=10.0, api_key="YOUR_API_KEY", ) ``` -------------------------------- ### Instantiate NearMatchDetail Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/models.md Example of creating a NearMatchDetail instance with specific values for a CSAM classification. ```python from arachnid_shield_sdk import NearMatchDetail, MediaClassification detail = NearMatchDetail( timestamp=15.5, sha1_base32="ABCDEFGHIJKLMNOPQRSTUVWXYZ723456", sha256_hex="2DB0DA447137B17D49988EEEFC5AD73A58EF9F28215078D1D2F4263423BC4508", classification=MediaClassification.CSAM ) ``` -------------------------------- ### Scan Media from URL with Config (Async) Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Asynchronous version of scan_media_from_url_with_config. Must be awaited. Returns and raises the same as the synchronous version. ```python async def scan_media_from_url_with_config( self, config: ScanMediaFromUrl, timeout: Optional[httpx.Timeout] = TIMEOUT_READ_PERMISSIVE ) -> ScannedMedia: pass ``` -------------------------------- ### Initialize ArachnidShield with String Credentials Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/configuration.md Instantiate the ArachnidShield client using string-based username and password credentials. ```python from arachnid_shield_sdk import ArachnidShield # String credentials shield = ArachnidShield(username="your_username", password="your_password") ``` -------------------------------- ### PDQ Scan Request Body Example Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/endpoints.md This JSON object defines the structure for submitting a batch of base64-encoded PDQ hashes for scanning. ```json { "hashes": [ "base64_encoded_pdq_hash_1", "base64_encoded_pdq_hash_2", "base64_encoded_pdq_hash_3" ] } ``` -------------------------------- ### Scan Media from Bytes with Config (Async) Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Use this asynchronous method to scan media content provided as bytes, along with a specific configuration. This method must be awaited. ```python async def scan_media_from_bytes_with_config( self, config: ScanMediaFromBytes, timeout: Optional[httpx.Timeout] = TIMEOUT_WRITE_PERMISSIVE ) -> ScannedMedia: # Method implementation details would be here pass ``` -------------------------------- ### Instantiate MatchDetails Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/models.md Create a MatchDetails object with hash values, distance, and classification. The distance parameter indicates the perceptual similarity between media. ```python from arachnid_shield_sdk import MatchDetails, MediaClassification match = MatchDetails( sha1_base32="4523EFGHIJKLMNOPQRSTUVWXYZ723456", sha256_hex="ABCDDA447137B17D49988EEEFC5AD73A58EF9F28215078D1D2F4263423BC4508", distance=1300, classification=MediaClassification.CSAM ) ``` -------------------------------- ### Handle ArachnidShieldException Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/types.md Example of how to catch an ArachnidShieldException and access the detailed error message. This is useful for providing user-friendly feedback when API calls fail. ```python from arachnid_shield_sdk.exceptions import ArachnidShieldException try: scanned = shield.scan_media_from_file(filepath) except ArachnidShieldException as e: print(f"Error: {e.detail.detail}") ``` -------------------------------- ### Catch HTTP Connection Errors Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/errors.md This example shows how to catch both ArachnidShieldException for API-specific errors and general httpx.HTTPError for connection failures, timeouts, and other network-related issues. ```python import httpx try: scanned = shield.scan_media_from_bytes(contents, mime_type) except ArachnidShieldException as e: print(f"API error: {e}") except httpx.HTTPError as e: # Catches connection failures, timeouts, etc. print(f"HTTP error: {e}") ``` -------------------------------- ### Catch Specific ArachnidShieldException Errors Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/errors.md This example demonstrates how to catch ArachnidShieldException and differentiate between specific error messages like hostname authorization or invalid credentials. ```python from arachnid_shield_sdk import ArachnidShield, ArachnidShieldException shield = ArachnidShield(username="user", password="pass") try: scanned = shield.scan_media_from_bytes(contents, mime_type) except ArachnidShieldException as e: if "Hostname not authorized" in str(e): print("This URL is not authorized for your account") elif "Authorization" in str(e): print("Invalid credentials") else: print(f"API error: {e}") ``` -------------------------------- ### scan_media_from_url_with_config (Async) Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Asynchronously scans media from a given URL using the provided configuration. This method is the asynchronous counterpart to `ArachnidShield.scan_media_from_url_with_config` and must be awaited. It returns the same types and raises the same exceptions as its synchronous version. ```APIDOC ## Method: scan_media_from_url_with_config (Async) ### Description Asynchronously scans media from a given URL using the provided configuration. This method is the asynchronous counterpart to `ArachnidShield.scan_media_from_url_with_config` and must be awaited. It returns the same types and raises the same exceptions as its synchronous version. ### Signature ```python async def scan_media_from_url_with_config( self, config: ScanMediaFromUrl, timeout: Optional[httpx.Timeout] = TIMEOUT_READ_PERMISSIVE ) -> ScannedMedia ``` ### Parameters - **config** (ScanMediaFromUrl) - Required - Configuration object for scanning media from a URL. - **timeout** (Optional[httpx.Timeout]) - Optional - Timeout configuration for the HTTP request. Defaults to `TIMEOUT_READ_PERMISSIVE`. ``` -------------------------------- ### PDQ Scan Success Response Example Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/endpoints.md This JSON object shows the structure of a successful response, detailing the classification and match details for each scanned PDQ hash. ```json { "scanned_hashes": { "base64_encoded_pdq_hash_1": { "classification": "no-known-match", "match_type": null, "near_match_details": null }, "base64_encoded_pdq_hash_2": { "classification": "csam", "match_type": "near", "near_match_details": { "timestamp": 0.0, "sha1_base32": "ABCDEFGHIJKLMNOPQRSTUVWXYZ723456", "sha256_hex": "2DB0DA447137B17D49988EEEFC5AD73A58EF9F28215078D1D2F4263423BC4508", "classification": "csam" } } } } ``` -------------------------------- ### Asynchronous Client Initialization Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/MANIFEST.txt Initialize the asynchronous ArachnidShieldAsync client. Configure with base URL, timeout, and authentication. ```python from arachnid_shield.client import ArachnidShieldAsync client = ArachnidShieldAsync( base_url="https://api.example.com", timeout=10.0, api_key="YOUR_API_KEY", ) ``` -------------------------------- ### scan_media_from_bytes_with_config (Async) Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Asynchronously scans media content provided as bytes, using a specific configuration. This method is the asynchronous equivalent of `ArachnidShield.scan_media_from_bytes_with_config` and must be awaited. It provides the same return values and raises the same exceptions as the synchronous version. ```APIDOC ## Method: scan_media_from_bytes_with_config (Async) ### Description Asynchronously scans media content provided as bytes, using a specific configuration. ### Parameters - **config** (ScanMediaFromBytes) - Required - The configuration object for scanning media from bytes. - **timeout** (Optional[httpx.Timeout]) - Optional - Specifies a timeout for the request. Defaults to `TIMEOUT_WRITE_PERMISSIVE`. ### Returns - **ScannedMedia** - An object containing the results of the media scan. ### Raises - Same exceptions as the synchronous version. ``` -------------------------------- ### Common Error Scenarios Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/exceptions.md Illustrates common error scenarios handled by ArachnidShieldException, including authentication, hostname authorization, and server errors, with corresponding code examples. ```APIDOC ### Common Error Scenarios #### Authentication Error (401) Raised when credentials are missing or invalid. ```python try: # Using invalid credentials shield = ArachnidShield(username="invalid", password="invalid") scanned = shield.scan_media_from_bytes(contents, "image/jpeg") except ArachnidShieldException as e: if "Authorization" in str(e): print("Invalid credentials provided") print(f"Details: {e.detail.detail}") ``` #### Hostname Not Authorized (403) Raised when the user's credentials don't permit scanning from the requested hostname. ```python try: scanned = shield.scan_media_from_url("https://unauthorized-domain.com/image.jpeg") except ArachnidShieldException as e: if "Hostname not authorized" in str(e): print("This domain is not authorized for your account") ``` #### Server Error (5xx) Raised on server-side errors. ```python try: scanned = shield.scan_media_from_bytes(contents, mime_type) except ArachnidShieldException as e: print(f"API server error: {e.detail.detail}") ``` ``` -------------------------------- ### Configure Base URL Directly in Base Class Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/configuration.md Demonstrates how the base URL can be passed directly during initialization, though this is typically handled internally by the SDK. ```python from arachnid_shield_sdk.api.client import _ArachnidShield # Not typically used directly, but shows the mechanism # class._ArachnidShield.__init__( # username="user", # password="pass", # base_url="https://custom-api.example.com/" # ) ``` -------------------------------- ### Initialize ArachnidShield with Bytes Credentials Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/configuration.md Instantiate the ArachnidShield client using bytes-based username and password credentials. This is an unusual but supported method. ```python # Bytes credentials (unusual but supported) shield = ArachnidShield(username=b"your_username", password=b"your_password") ``` -------------------------------- ### Instantiate ScannedMedia Object Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/models.md Create a ScannedMedia instance with media details, classification, and match information. Ensure all required parameters like size_bytes, sha1_base32, and sha256_hex are provided. ```python from arachnid_shield_sdk import ScannedMedia, NearMatchDetail, MediaClassification, MatchType scanned = ScannedMedia( size_bytes=24335, sha1_base32="TTY4MGOMVNR5KI2ZZ62EMYDZALUTBOHN", sha256_hex="8C3B43FB9BA63B7120CEDF87BC9F348BBAAF5D39A97266D0C7587B5EFD6ABA2D", classification=MediaClassification.CSAM, match_type=MatchType.Near, near_match_details=[...] ) ``` -------------------------------- ### Process Near Match Details Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/types.md Example of how to process scan results to identify and print details of near matches found in media. Requires a scan result object with a `near_match_details` attribute. ```python scanned = shield.scan_media_from_bytes(contents, "video/mp4") if scanned.near_match_details: for detail in scanned.near_match_details: print(f"Near match found at {detail.timestamp}s") print(f" Classification: {detail.classification}") print(f" SHA256: {detail.sha256_hex}") ``` -------------------------------- ### Correct Usage of ScanMediaFromUrl Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/errors.md Demonstrates the correct usage of `ScanMediaFromUrl` by providing a valid URL string. ```python from arachnid_shield_sdk import ScanMediaFromUrl config = ScanMediaFromUrl(url="https://example.com/image.jpeg") ``` -------------------------------- ### Base Client Class Definition Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/module-structure.md Defines the internal base client class `_ArachnidShield` which handles authentication and HTTP client setup. The base URL can be configured via an environment variable. ```python DEFAULT_BASE_URL = "https://shield.projectarachnid.com/" class _ArachnidShield: def __init__( self, username: Union[str, bytes], password: Union[str, bytes], base_url: str = os.getenv("ARACHNID_SHIELD_URL", DEFAULT_BASE_URL) ) @property def base_url(self) -> str def _build_sync_http_client(self) -> httpx.Client def _build_async_http_client(self) -> httpx.AsyncClient ``` -------------------------------- ### Scan Media from URL with Configuration Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/MANIFEST.txt Scan media from a URL with custom configuration options applied to the request. ```python from arachnid_shield.models import ScanMediaFromUrl scan_request = ScanMediaFromUrl(url="https://example.com/path/to/media.jpg") result = client.scan_media_from_url_with_config(scan_request) ``` -------------------------------- ### Scan Media from Bytes with Configuration Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/MANIFEST.txt Scan media from bytes with custom configuration options applied to the request. ```python from arachnid_shield.models import ScanMediaFromBytes with open("/path/to/your/media.jpg", "rb") as f: media_bytes = f.read() scan_request = ScanMediaFromBytes(media=media_bytes) result = client.scan_media_from_bytes_with_config(scan_request) ``` -------------------------------- ### Scan Media from URL (Async) Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Use this asynchronous method to scan media content from a given URL. The SDK will fetch the content from the URL for scanning. This method must be awaited. ```python async def scan_url(): shield = ArachnidShieldAsync(username="user", password="pass") scanned_media = await shield.scan_media_from_url("https://example.com/image.jpeg") return scanned_media ``` -------------------------------- ### Django Integration for Media Scanning Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/usage-patterns.md Integrate the Arachnid Shield SDK into a Django view for scanning uploaded media files. This example uses Django's request handling and JSON response mechanisms. ```python import pathlib from django.http import JsonResponse from django.views.decorators.http import require_http_methods from arachnid_shield_sdk import ArachnidShield, ArachnidShieldException shield = ArachnidShield(username="user", password="pass") @require_http_methods(["POST"]) def scan_media(request): if 'file' not in request.FILES: return JsonResponse({"error": "No file provided"}, status=400) file = request.FILES['file'] mime_type = file.content_type try: scanned = shield.scan_media_from_bytes(file.read(), mime_type) return JsonResponse({ "sha256": scanned.sha256_hex, "classification": str(scanned.classification), "matches_known_media": scanned.matches_known_media }) except ArachnidShieldException as e: return JsonResponse({"error": str(e)}, status=400) except Exception as e: return JsonResponse({"error": "Scan failed"}, status=500) ``` -------------------------------- ### Scan Media from Bytes (Async) Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Asynchronously scan media content provided as bytes. Ensure the media is opened in binary read mode and the correct MIME type is specified. ```python async def scan_media(): shield = ArachnidShieldAsync(username="user", password="pass") with open("image.jpeg", "rb") as f: contents = f.read() scanned_media = await shield.scan_media_from_bytes(contents, "image/jpeg") return scanned_media ``` -------------------------------- ### Asynchronous Scan Media from File Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/MANIFEST.txt Asynchronously scan a media file from the local filesystem using the ArachnidShieldAsync client. Use with await. ```python async def scan_file(client: ArachnidShieldAsync): result = await client.scan_media_from_file( "/path/to/your/media.jpg", ) return result ``` -------------------------------- ### Asynchronous Media Scanning with Arachnid Shield SDK Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/README.md Utilize the ArachnidShieldAsync client for asynchronous operations in async environments. The interface is identical to the synchronous client, but methods are awaitable coroutines. This example demonstrates scanning image bytes asynchronously. ```python import asyncio from arachnid_shield_sdk import ArachnidShieldAsync as ArachnidShield shield = ArachnidShield(username="", password="") async def process_media(contents): scanned_media = await shield.scan_media_from_bytes(contents, "image/jpeg") if scanned_media.matches_known_image: print(f"harmful media found!: {scanned_media}") ... async def main(): with open("some-image.jpeg", "rb") as f: contents = f.read() await process_media(contents) if __name__ == '__main__': asyncio.get_event_loop().run_until_complete(main()) ``` -------------------------------- ### Correct Usage of ScanMediaFromBytes with Bytes and BytesIO Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/errors.md Demonstrates the correct usage of `ScanMediaFromBytes` with both `bytes` and `io.BytesIO` for the `contents` parameter. ```python from arachnid_shield_sdk import ScanMediaFromBytes import io # Correct usage with bytes config1 = ScanMediaFromBytes(contents=b"jpeg data", mime_type="image/jpeg") # Correct usage with BytesIO config2 = ScanMediaFromBytes(contents=io.BytesIO(b"jpeg data"), mime_type="image/jpeg") ``` -------------------------------- ### Initialize ArachnidShield Client Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/configuration.md Instantiate the ArachnidShield client with your API username and password for authentication. ```python ArachnidShield(username: Union[str, bytes], password: Union[str, bytes]) ``` -------------------------------- ### ScanMediaFromBytes Class Constructor Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/models.md Configuration for scanning media provided as raw bytes. The constructor requires media contents (bytes or BytesIO) and its MIME type. ```APIDOC ## Class: ScanMediaFromBytes Configuration for scanning media provided as raw bytes. ### Constructor ```python ScanMediaFromBytes( contents: Union[bytes, io.BytesIO], mime_type: str ) ``` #### Parameters - **contents** (bytes or io.BytesIO) - Required - Raw media bytes or BytesIO stream - **mime_type** (str) - Required - MIME type of media (e.g., "image/jpeg") #### Raises `ValueError` if validation fails (invalid types) #### Example ```python from arachnid_shield_sdk import ScanMediaFromBytes import io # Using bytes with open("image.jpeg", "rb") as f: contents = f.read() config1 = ScanMediaFromBytes(contents=contents, mime_type="image/jpeg") # Using BytesIO buffer = io.BytesIO(contents) config2 = ScanMediaFromBytes(contents=buffer, mime_type="image/jpeg") scanned = shield.scan_media_from_bytes_with_config(config1) ``` ### Method: to_dict Converts to dictionary for serialization. ### Method: from_dict Constructs from dictionary. ``` -------------------------------- ### Initialize PDQMatch Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/models.md Construct a PDQMatch object with classification, match type, and optional near-match details. This represents the outcome of scanning a single PDQ hash. ```python PDQMatch( classification: MediaClassification, match_type: Optional[MatchType], near_match_details: Optional[NearMatchDetail] ) ``` -------------------------------- ### Scan Media from File (Async) Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Use this asynchronous method to scan media content directly from a local file path. Ensure the filepath is correctly specified. This method must be awaited. ```python import pathlib async def scan_file(): shield = ArachnidShieldAsync(username="user", password="pass") filepath = pathlib.Path("/path/to/image.jpeg") scanned_media = await shield.scan_media_from_file(filepath) return scanned_media ``` -------------------------------- ### Instantiate VisualMatchDetails Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/models.md Create a VisualMatchDetails object, which aggregates multiple MatchDetails. It includes a timestamp for when the match was detected. Defaults to an empty list of matches. ```python from arachnid_shield_sdk import VisualMatchDetails, MatchDetails, MediaClassification # Example with matches match_details_list = [ MatchDetails( sha1_base32="4523EFGHIJKLMNOPQRSTUVWXYZ723456", sha256_hex="ABCDDA447137B17D49988EEEFC5AD73A58EF9F28215078D1D2F4263423BC4508", distance=1300, classification=MediaClassification.CSAM ) ] visual_match = VisualMatchDetails(timestamp=1678886400.0, matches=match_details_list) ``` -------------------------------- ### Configure ScanMediaFromBytes with Bytes Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/models.md Create a ScanMediaFromBytes configuration using raw bytes content. Ensure the MIME type is correctly specified. This is used for scanning media directly from memory. ```python from arachnid_shield_sdk import ScanMediaFromBytes import io # Using bytes with open("image.jpeg", "rb") as f: contents = f.read() config1 = ScanMediaFromBytes(contents=contents, mime_type="image/jpeg") # Using BytesIO buffer = io.BytesIO(contents) config2 = ScanMediaFromBytes(contents=buffer, mime_type="image/jpeg") scanned = shield.scan_media_from_bytes_with_config(config1) ``` -------------------------------- ### Scan Media from URL with Configuration Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Use this method to scan media content located at a specific URL. It requires a ScanMediaFromUrl configuration object, which includes the URL to be scanned. The timeout parameter can be adjusted for specific needs. ```python from arachnid_shield_sdk import ScanMediaFromUrl config = ScanMediaFromUrl(url="https://example.com/image.jpeg") scanned_media = shield.scan_media_from_url_with_config(config) ``` -------------------------------- ### Scanning Media from URL with Arachnid Shield SDK Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/module-structure.md This flow illustrates scanning media content from a given URL using the `ArachnidShield` client. It involves creating a `ScanMediaFromUrl` object and then using the `scan_media_from_url_with_config` method, which sends a POST request to the `/v1/url/` endpoint with the URL in the request body. The result is parsed into a `ScannedMedia` object. ```text User code │ └──> ArachnidShield.scan_media_from_url(url) │ ├──> Creates ScanMediaFromUrl(url) │ └──> ArachnidShield.scan_media_from_url_with_config(config) │ ├──> POST /v1/url/ │ Content-Type: application/json │ Body: {"url": url} │ └──> ScannedMedia.from_dict(response.json()) │ └──> ScannedMedia ``` -------------------------------- ### scan_media_from_url (Async) Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Asynchronously scans media content from a given URL. This is the asynchronous version of `ArachnidShield.scan_media_from_url` and requires awaiting. It mirrors the return values and exceptions of its synchronous counterpart. ```APIDOC ## Method: scan_media_from_url (Async) ### Description Asynchronously scans media content from a provided URL. ### Parameters - **url** (str) - Required - The URL of the media to be scanned. - **timeout** (Optional[httpx.Timeout]) - Optional - Specifies a timeout for the request. Defaults to `TIMEOUT_READ_PERMISSIVE`. ### Returns - **ScannedMedia** - An object containing the results of the media scan. ### Raises - Same exceptions as the synchronous version. ### Example ```python async def scan_url(): shield = ArachnidShieldAsync(username="user", password="pass") scanned_media = await shield.scan_media_from_url("https://example.com/image.jpeg") return scanned_media ``` ``` -------------------------------- ### scan_media_from_bytes (Async) Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Asynchronously scans media content from bytes. This is the asynchronous version of `ArachnidShield.scan_media_from_bytes` and must be awaited. ```APIDOC ## Method: scan_media_from_bytes (Async) Asynchronous version of `ArachnidShield.scan_media_from_bytes`. ```async async def scan_media_from_bytes( self, contents: Union[bytes, io.BytesIO], mime_type: str, timeout: Optional[httpx.Timeout] = TIMEOUT_WRITE_PERMISSIVE ) -> ScannedMedia: ``` Returns and raises same as synchronous version. Must be awaited. **Example:** ```python async def scan_media(): shield = ArachnidShieldAsync(username="user", password="pass") with open("image.jpeg", "rb") as f: contents = f.read() scanned_media = await shield.scan_media_from_bytes(contents, "image/jpeg") return scanned_media ``` ``` -------------------------------- ### Async Runtime Usage Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/configuration.md Use this snippet to integrate the ArachnidShieldAsync client within an async/await context. It demonstrates initializing the client and performing a media scan operation. Ensure you have an active asyncio event loop. ```python import asyncio from arachnid_shield_sdk import ArachnidShieldAsync async def main(): shield = ArachnidShieldAsync(username="user", password="pass") scanned = await shield.scan_media_from_bytes(contents, mime_type) return scanned # Run with asyncio result = asyncio.run(main()) # Or in an existing event loop asyncio.get_event_loop().run_until_complete(main()) ``` -------------------------------- ### Asynchronous Scan Media from URL Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/MANIFEST.txt Asynchronously scan media content from a URL using the ArachnidShieldAsync client. Use with await. ```python async def scan_url(client: ArachnidShieldAsync): result = await client.scan_media_from_url( "https://example.com/path/to/media.jpg", ) return result ``` -------------------------------- ### Initialize ScannedPDQHashes Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/models.md Instantiate ScannedPDQHashes with a dictionary mapping PDQ hashes to their match results. This is typically the result of a batch scan operation. ```python ScannedPDQHashes(scanned_hashes: Dict[str, PDQMatch]) ``` -------------------------------- ### Scan Media from Local File Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/MANIFEST.txt Scan a media file from the local filesystem using the synchronous client. Requires the file path. ```python result = client.scan_media_from_file( "/path/to/your/media.jpg", ) ``` -------------------------------- ### Scan Media from Bytes with Configuration Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Use this method to scan media content provided as bytes. It requires a ScanMediaFromBytes configuration object, specifying the media contents and MIME type. The timeout parameter can be adjusted for specific needs. ```python from arachnid_shield_sdk import ScanMediaFromBytes config = ScanMediaFromBytes(contents=media_bytes, mime_type="image/jpeg") scanned_media = shield.scan_media_from_bytes_with_config(config) ``` -------------------------------- ### Python Base64 Encoding for Credentials Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/endpoints.md Demonstrates how to base64 encode username and password for HTTP Basic Authentication. The SDK handles this automatically. ```python import base64 username = "your_username" password = "your_password" credentials = base64.b64encode(f"{username}:{password}".encode()).decode() # Use credentials in Authorization header ``` -------------------------------- ### scan_media_from_file (Async) Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Asynchronously scans media content from a local file. This method is the asynchronous counterpart to the synchronous `scan_media_from_file` and must be awaited. It returns the same results and raises the same exceptions as its synchronous version. ```APIDOC ## Method: scan_media_from_file (Async) ### Description Asynchronously scans media content from a local file. ### Parameters - **filepath** (pathlib.Path) - Required - The path to the file to be scanned. - **mime_type_override** (Optional[str]) - Optional - Allows overriding the detected MIME type of the file. - **timeout** (Optional[httpx.Timeout]) - Optional - Specifies a timeout for the request. Defaults to `TIMEOUT_WRITE_PERMISSIVE`. ### Returns - **ScannedMedia** - An object containing the results of the media scan. ### Raises - Same exceptions as the synchronous version. ### Example ```python import pathlib async def scan_file(): shield = ArachnidShieldAsync(username="user", password="pass") filepath = pathlib.Path("/path/to/image.jpeg") scanned_media = await shield.scan_media_from_file(filepath) return scanned_media ``` ``` -------------------------------- ### ArachnidShield Client Initialization Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/INDEX.md Initializes the ArachnidShield client for synchronous operations. Configuration includes base URL, timeouts, and authentication. ```APIDOC ## ArachnidShield (Sync Client) ### Description Initializes the synchronous client for interacting with the Arachnid Shield API. ### Constructor Parameters - **base_url** (string, optional) - The base URL for the API. Defaults to the official Arachnid Shield API endpoint. - **timeout_write_permissive** (float, optional) - Timeout for write operations in seconds. - **timeout_read_permissive** (float, optional) - Timeout for read operations in seconds. - **api_key** (string, optional) - API key for authentication. Can also be set via `ARACHNID_SHIELD_API_KEY` environment variable. ### Example ```python from arachnid_shield_sdk import ArachnidShield client = ArachnidShield(base_url="https://api.example.com", timeout_read_permissive=30.0) ``` ``` -------------------------------- ### Configure Batch Scan from PDQ Hashes Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/models.md Use this model for batch scanning when you have a list of PDQ hashes. Provide a list of base64-encoded PDQ hashes to initiate the scan. ```python from arachnid_shield_sdk import ScanMediaFromPdq config = ScanMediaFromPdq(hashes=["hash1_base64", "hash2_base64", "hash3_base64"]) result = shield.scan_pdq_hashes(config) ``` -------------------------------- ### Asynchronous Scan Media from Bytes Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/MANIFEST.txt Asynchronously scan media content provided as bytes using the ArachnidShieldAsync client. Use with await. ```python async def scan_bytes(client: ArachnidShieldAsync): with open("/path/to/your/media.jpg", "rb") as f: media_bytes = f.read() result = await client.scan_media_from_bytes(media_bytes) return result ``` -------------------------------- ### Synchronous Media Scanning Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/README.md Instantiate the synchronous ArachnidShield client and scan media content from bytes. Check the scan results for matches. ```python from arachnid_shield_sdk import ArachnidShield shield = ArachnidShield(username="your_username", password="your_password") scanned = shield.scan_media_from_bytes(contents, "image/jpeg") if scanned.matches_known_media: print(f"Harmful content: {scanned.classification}") ``` -------------------------------- ### scan_pdq_hashes (Async) Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/client.md Asynchronously scans PDQ hashes using the provided configuration. This is the asynchronous version of `ArachnidShield.scan_pdq_hashes` and requires awaiting. It mirrors the return types and exceptions of its synchronous counterpart. ```APIDOC ## Method: scan_pdq_hashes (Async) ### Description Asynchronously scans PDQ hashes using the provided configuration. This is the asynchronous version of `ArachnidShield.scan_pdq_hashes` and requires awaiting. It mirrors the return types and exceptions of its synchronous counterpart. ### Signature ```python async def scan_pdq_hashes( self, config: ScanMediaFromPdq, timeout: Optional[httpx.Timeout] = TIMEOUT_READ_PERMISSIVE ) -> ScannedPDQHashes ``` ### Parameters - **config** (ScanMediaFromPdq) - Required - Configuration object containing the PDQ hashes to scan. - **timeout** (Optional[httpx.Timeout]) - Optional - Timeout configuration for the HTTP request. Defaults to `TIMEOUT_READ_PERMISSIVE`. ### Example ```python import asyncio from arachnid_shield_sdk import ArachnidShieldAsync, ScanMediaFromPdq async def scan_hashes(): shield = ArachnidShieldAsync(username="user", password="pass") config = ScanMediaFromPdq(hashes=["hash1", "hash2"]) result = await shield.scan_pdq_hashes(config) return result asyncio.run(scan_hashes()) ``` ``` -------------------------------- ### ScanMediaFromUrl Configuration Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/types.md Use ScanMediaFromUrl to configure media scanning from a web URL. The URL must be a valid string representing the media's location. ```python from arachnid_shield_sdk import ScanMediaFromUrl config = ScanMediaFromUrl(url="https://example.com/image.jpeg") scanned = shield.scan_media_from_url_with_config(config) ``` -------------------------------- ### Media Class Constructor Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/models.md Represents media in the Arachnid Shield database. The constructor takes SHA1 and SHA256 hashes, and an optional classification. ```APIDOC ## Class: Media Simplified representation of media in the Arachnid Shield database. ### Constructor ```python Media( sha1_base32: str, sha256_hex: str, classification: Optional[MediaClassification] = None ) ``` #### Parameters - **sha1_base32** (str) - Required - Base-32 SHA1 hash of media - **sha256_hex** (str) - Required - Hexadecimal SHA256 hash of media - **classification** (Optional[MediaClassification]) - Optional - Classification assigned to media #### Example ```python from arachnid_shield_sdk import Media, MediaClassification media = Media( sha1_base32="ABCDEFGHIJKLMNOPQRSTUVWXYZ723456", sha256_hex="2DB0DA447137B17D49988EEEFC5AD73A58EF9F28215078D1D2F4263423BC4508", classification=MediaClassification.CSAM ) ``` ### Method: to_dict Converts to dictionary representation. ### Method: from_dict Constructs from dictionary, handling optional classification. ``` -------------------------------- ### Scan Media from URL Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/MANIFEST.txt Scan media content directly from a URL using the synchronous client. The SDK will fetch the content. ```python result = client.scan_media_from_url( "https://example.com/path/to/media.jpg", ) ``` -------------------------------- ### Create Media Object Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/api-reference/models.md Instantiate a Media object with SHA1 and SHA256 hashes, and an optional classification. Use this to represent media stored in the Arachnid Shield database. ```python from arachnid_shield_sdk import Media, MediaClassification media = Media( sha1_base32="ABCDEFGHIJKLMNOPQRSTUVWXYZ723456", sha256_hex="2DB0DA447137B17D49988EEEFC5AD73A58EF9F28215078D1D2F4263423BC4508", classification=MediaClassification.CSAM ) ``` -------------------------------- ### Asynchronous Media Scanning Source: https://github.com/cdncentreforchildprotection/arachnid-shield-sdk-python/blob/main/_autodocs/README.md Instantiate the asynchronous ArachnidShieldAsync client and scan media content from bytes within an async function. Run the async function using asyncio. ```python import asyncio from arachnid_shield_sdk import ArachnidShieldAsync async def main(): shield = ArachnidShieldAsync(username="user", password="pass") scanned = await shield.scan_media_from_bytes(contents, "image/jpeg") return scanned result = asyncio.run(main()) ```