Skip to main content

Apptrail Application Events SDK for Python

Project description

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

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

apptrail-application-events-sdk-0.0.3.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file apptrail-application-events-sdk-0.0.3.tar.gz.

File metadata

  • Download URL: apptrail-application-events-sdk-0.0.3.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for apptrail-application-events-sdk-0.0.3.tar.gz
Algorithm Hash digest
SHA256 22c25922f9f33a16ba104e9d29173165140e5b4eaca5277cd0161b4a693e06f2
MD5 ee487ade7f34cd67e4ecc7d68abe310d
BLAKE2b-256 1dc229497d67459523d2fb8fd837dfe4d35ef8dbf6d90dd22eecae3a61491e79

See more details on using hashes here.

File details

Details for the file apptrail_application_events_sdk-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: apptrail_application_events_sdk-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for apptrail_application_events_sdk-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 434648513b61e9027ab99584d50e8bf4fe1b8eb89abff2d3e096fb154ac842c5
MD5 64c9b6d1cee3f567afc10d53ba71b9a9
BLAKE2b-256 98d3ed7490b7f9c7a712998f8bc7616e7e6e48646e22f9dad0ef56adf586fb18

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