Skip to main content

Apptrail Application Events SDK for Python

You can use the Apptrail Application Events SDK for Python to send audit logs from your Python applications to your customers.

Learn more

Notes and tips

  • Requires Python >= 3.6
  • Instantiate the client once at the top of your application and reuse it to prevent unnecessary recreation.

Installing

The Events SDK is published to PyPI.

pip install apptrail-application-events-sdk

Instantiating client

from apptrail_application_events_sdk import ApptrailEventsClient

my_api_key = load_secret_api_Key()
my_region = "us-west-2";

events_client = ApptrailEventsClient(
  region=my_region,
  api_key=my_api_key,
)

Sending an event

event = {
  "tenantId": "cust_MGY4MmYzNDMtZjEwOC00OWI",
  "eventName": "CreateRepository",
  "eventTime": "2022-01-26T06:01:00Z",
  "actor": {
    "id": "acct_MmRlODllZDctM2I0Yi0",
    "details": {
      "type": "account",
      "name": "API Access",
    },
  },
  "resources": [
    {
      "id": "repo_YWI5NjkzY2UtNzI1Ny00N",
      "details": {
        "repositoryType": "V2",
      },
    },
  ],
  "context": {
    "sourceIpAddress": "103.6.179.245",
    "userAgent": "Apache-HttpClient/4.5.3 (Java/11.0.11)",
  }
  "tags": {
    "severity": "LOW",
  },
  "eventDetails": {
    "request": {
      "repositoryName": "my-repository",
    },
  },
};

events_client.put_event(event)

Sending multiple events

events = [...]

events_client.put_events(events)

Handling errors

As a best practice, you should handle errors while sending events, especially if you are sending critical logs. The Events client includes automatic retries with backoff, but errors can happen due to rare server issues or client side issues.

You can choose what to do with failing events. For example, you may sideline them to disk, or a dead letter queue for retry or remediation.

from apptrail_application_events_sdk import ApptrailError

try:
  events_client.put_event(event)
except ApptrailError as e:
  # handle error
except Exception as e:
  # handle

Logging

You can enable logging from the Apptrail Events SDK, from your application using the Python logging library. The Apptrail Events SDK uses a standard logger named apptrail that you can configure.

import logging
from apptrail_application_events import ApptrailEventsClient

apptrail_logger = logging.getLogger('apptrail')
apptrail_logger.addHandler(logging.StreamHandler())
apptrail_logger.setLevel(logging.DEBUG)

# use SDK

Metadata

Release files for apptrail-application-events-sdk 0.0.3

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

Source distribution (sdist)

Source distribution for apptrail-application-events-sdk 0.0.3
File Size Uploaded Provenance
apptrail-application-events-sdk-0.0.3.tar.gz 8.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for apptrail-application-events-sdk 0.0.3
File Interpreter ABI Platform
apptrail_application_events_sdk-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 15.6 kB

Release files / apptrail-application-events-sdk-0.0.3.tar.gz

Download URL apptrail-application-events-sdk-0.0.3.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
22c25922f9f33a16ba104e9d29173165140e5b4eaca5277cd0161b4a693e06f2
BLAKE2b-256 checksum
How to use checksums
1dc229497d67459523d2fb8fd837dfe4d35ef8dbf6d90dd22eecae3a61491e79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.6.4 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.8

Release files / apptrail_application_events_sdk-0.0.3-py3-none-any.whl

Download URL apptrail_application_events_sdk-0.0.3-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
434648513b61e9027ab99584d50e8bf4fe1b8eb89abff2d3e096fb154ac842c5
BLAKE2b-256 checksum
How to use checksums
98d3ed7490b7f9c7a712998f8bc7616e7e6e48646e22f9dad0ef56adf586fb18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.6.4 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.8

Security for apptrail-application-events-sdk 0.0.3

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.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files No provenance

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