Skip to main content

scanner-client

This is the Python SDK for the Scanner API. It is autogenerated from an OpenAPI v3 spec.

You can use the SDK for use cases like these:

  • Execute queries on your log files in S3 that have been indexed by Scanner.
  • Create, read, and update detection rules
  • Manage event sinks, which are destinations for detection alerts.

Documentation

You can view the API documentation for the Scanner API here.

Usage

To install the SDK, run:

pip install scanner-client

Create the client by passing in the API URL and API key, which you can get from Settings > API Keys in the Scanner UI.

import os
from scanner_client import Scanner

scanner = Scanner(
    api_url=os.environ["SCANNER_API_URL"],
    api_key=os.environ["SCANNER_API_KEY"],
)

Synchronously query logs over last 30 days

import os
import time

from datetime import datetime, timezone, timedelta
from scanner_client import Scanner

scanner = Scanner(
    api_url=os.environ["SCANNER_API_URL"],
    api_key=os.environ["SCANNER_API_KEY"],
)

end_time = datetime.now(tz=timezone.utc)
start_time = end_time - timedelta(days=30)

query_text = """
	%ingest.source_type: "aws:cloudtrail"
	eventSource: "s3.amazonaws.com"
	| stats by eventName
"""

# Run blocking query, which runs for up to 60 seconds and returns results.

response = scanner.query.blocking_query(
    query_text=query_text,
    start_time=start_time.isoformat()
    end_time=end_time.isoformat()
)
print(response.results)

# Run non-blocking query and periodically checking for completion.
# Can run for 15 minutes.

qr_id = scanner.query.start_query(
    query_text=query_text,
    start_time=start_time.isoformat()
    end_time=end_time.isoformat()
).qr_id

while True:
    print("Checking query progress")
    query_progress = scanner.query.query_progress(qr_id)
    if query_progress.is_completed:
        print(query_progress.results)
        break

    time.sleep(1)

# Run non-blocking query and return results. This handles checking
# query progress and returns the results once the query is complete.

response = scanner.query.start_query_and_return_results(
    query_text=query_text,
    start_time=start_time.isoformat()
    end_time=end_time.isoformat()
)
print(response.results)

Async Scanner

The AsyncScanner class is also available for use with asyncio. All of the API methods are coroutines and can be awaited.

import asyncio
from scanner_client import AsyncScanner

# ...

scanner = AsyncScanner(
    api_url=os.environ["SCANNER_API_URL"],
    api_key=os.environ["SCANNER_API_KEY"],
)

# ...

response = await scanner.query.blocking_query(
    query_text=query_text,
    start_time=start_time.isoformat()
    end_time=end_time.isoformat()
)
print(response.results)

Metadata

Release files for scanner-client 0.1.1

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

Built distribution (wheel)

Table of built distributions (wheels) for scanner-client 0.1.1
File Interpreter ABI Platform Actions
scanner_client-0.1.1-py3-none-any.whl Python 3 none any Details for scanner_client-0.1.1-py3-none-any.whl

Release files / scanner_client-0.1.1-py3-none-any.whl

Download URL scanner_client-0.1.1-py3-none-any.whl
Size 180.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa148985866a47d5d1522004613c39fe2b2734d9ea3b823fdb97f9d18d0e132e
BLAKE2b-256 checksum
How to use checksums
092e731ad4f1d476519e7ede369770c0241fe2bec0a5819484cd189b15a854ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Security for scanner-client 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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