Skip to main content

A modern, modular, and complete Python SDK for the Darktrace API

Project description

🚀 Darktrace Python SDK

PyPI - Python Version GitHub License GitHub Repo stars

A modern, Pythonic SDK for the Darktrace Threat Visualizer API.


🆕 Latest Updates (v0.8.53)

  • Fix: ensure host URL includes protocol (default to https if missing)

✨ Features

  • Extensive API Coverage: Most endpoints, parameters, and actions from the official Darktrace API Guide are implemented.
  • Modular & Maintainable: Each endpoint group is a separate Python module/class.
  • Easy Authentication: Secure HMAC-SHA1 signature generation and token management.
  • Async-Ready: Designed for easy extension to async workflows.
  • Type Hints & Docstrings: Full typing and documentation for all public methods.
  • Comprehensive Documentation: Detailed documentation for every module and endpoint.

📦 Installation

pip install darktrace-sdk

After installation, you'll import it in Python as darktrace:

from darktrace import DarktraceClient

Or clone this repository:

git clone https://github.com/yourusername/darktrace.git
cd darktrace
pip install .

🚦 Quick Start

from darktrace import DarktraceClient

# Initialize the client
client = DarktraceClient(
    host="https://your-darktrace-instance",
    public_token="YOUR_PUBLIC_TOKEN",
    private_token="YOUR_PRIVATE_TOKEN"
)

# Access endpoint groups
devices = client.devices
all_devices = devices.get()

antigena = client.antigena
actions = antigena.get_actions()

# Use Advanced Search with POST requests (Darktrace 6.1+)
advanced_search = client.advanced_search
query = {
    "search": "@type:\"ssl\" AND @fields.dest_port:\"443\"",
    "fields": [],
    "offset": 0,
    "timeframe": "3600"  # 1 hour
}
results = advanced_search.search(query=query, post_request=True)

print(all_devices)
print(actions)
print(results)

📚 Documentation

Comprehensive documentation is available in the docs directory:

And many more modules covering every aspect of the Darktrace API.

See the EXAMPLES.md file for additional usage examples.


🛡️ Endpoint Coverage

This SDK aims to cover all endpoints in the Darktrace API Guide, including:

  • /advancedsearch (search, analyze, graph)
  • /aianalyst (incidentevents, groups, acknowledge, pin, comments, stats, investigations, incidents)
  • /antigena (actions, manual, summary)
  • /components, /cves, /details, /deviceinfo, /devices, /devicesearch, /devicesummary
  • /endpointdetails, /enums, /filtertypes, /intelfeed, /mbcomments, /metricdata, /metrics, /models, /modelbreaches, /network, /pcaps, /similardevices, /status, /subnets, /summarystatistics, /tags, and all /agemail endpoints

If you find a missing endpoint, open an issue or PR and it will be added!


⚠️ Known Issues

/devicesummary Endpoint Returns HTTP 500

The /devicesummary endpoint may return a 500 Internal Server Error when accessed with API tokens, even though it works in the browser or with session/cookie authentication. This is a known limitation of the Darktrace API backend and not a bug in the SDK or your code.

Workaround: There is currently no programmatic workaround. If you require this endpoint, please contact Darktrace support or use browser-based access where possible.

Status: Tracked as issue #37. If you encounter this, please reference the issue for updates.


📝 Contributing

Contributions are welcome! Please:

  1. Fork the repo and create your branch.
  2. Write clear, tested code and clean code principles.
  3. Add/Update docstrings and type hints.
  4. Submit a pull request with a detailed description.

📄 License

This project is licensed under the MIT License. See LICENSE for details.


🙏 Acknowledgements

  • Inspired by the official Darktrace API Guide
  • Community contributions welcome!

Made with ❤️ for the Darktrace community.

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

darktrace_sdk-0.8.53.tar.gz (32.2 kB view details)

Uploaded Source

Built Distribution

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

darktrace_sdk-0.8.53-py3-none-any.whl (47.7 kB view details)

Uploaded Python 3

File details

Details for the file darktrace_sdk-0.8.53.tar.gz.

File metadata

  • Download URL: darktrace_sdk-0.8.53.tar.gz
  • Upload date:
  • Size: 32.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for darktrace_sdk-0.8.53.tar.gz
Algorithm Hash digest
SHA256 6922b28204556612345c3ff83d6b13aedebe9ffd0f62d2bdd04f185d0719f1a9
MD5 b8df8fc3004a96d8ead58bcdb9bfaa31
BLAKE2b-256 e55f06b7b91cdd8ffa067566fa5bca9c6f297b47b47b1eb6e2829723d01742e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for darktrace_sdk-0.8.53.tar.gz:

Publisher: python-publish.yml on LegendEvent/darktrace-sdk

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

File details

Details for the file darktrace_sdk-0.8.53-py3-none-any.whl.

File metadata

  • Download URL: darktrace_sdk-0.8.53-py3-none-any.whl
  • Upload date:
  • Size: 47.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for darktrace_sdk-0.8.53-py3-none-any.whl
Algorithm Hash digest
SHA256 9c704d49e81472adaf2f98d4c7c822f703ea5b3a6e18dc22ba31eec1ec1493ae
MD5 f7b01a96248dbb55310ca1b7b6081049
BLAKE2b-256 f8e5f521da38f90089044286b184e8ea60acfa41bbe37c5bfee24519c7e150a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for darktrace_sdk-0.8.53-py3-none-any.whl:

Publisher: python-publish.yml on LegendEvent/darktrace-sdk

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

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