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.2.tar.gz (7.3 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.2.tar.gz.

File metadata

  • Download URL: apptrail-application-events-sdk-0.0.2.tar.gz
  • Upload date:
  • Size: 7.3 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.2.tar.gz
Algorithm Hash digest
SHA256 02eb4022ee8a794277b2c79868d9f9dbf153e66ba8c4de36f85dca1b6f02ffbd
MD5 17cf6e5ca3ceb58e6f265f36e48cb931
BLAKE2b-256 2c43d82e4c8557f0c5b83fabd190347795acdc69c62b82fe95132d1aadfb26a1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: apptrail_application_events_sdk-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a486aa3cd615b6bae4086054cce56a935fca653d560560b3c2194a2e45033fee
MD5 a5c5e8ba4eb5c1c8497f988291697e1b
BLAKE2b-256 a8332f1e6d3f482b6b38f5f72ddc7bfb313054a6bb381ab75a7186f0e7e59574

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