Skip to main content

Pangea API SDK

Project description

Pangea Logo

documentation Discourse

Pangea Python SDK

A Python SDK for integrating with Pangea services. Supports Python v3.9 and above.

Installation

GA releases

Via pip:

$ pip3 install pangea-sdk

Via poetry:

$ poetry add pangea-sdk

Beta releases

Pre-release versions may be available with the b (beta) denotation in the version number. These releases serve to preview beta services and APIs. Per Semantic Versioning, they are considered unstable and do not carry the same compatibility guarantees as stable releases. Beta changelog.

Via pip:

$ pip3 install pangea-sdk==3.8.0b2

Via poetry:

$ poetry add pangea-sdk==3.8.0b2

Usage

General usage would be to create a token for a service through the Pangea Console and then construct an API client for that respective service. The below example shows how this can be done for Secure Audit Log to log a simple event:

import os

from pangea.config import PangeaConfig
from pangea.services import Audit

# Load client configuration from environment variables `PANGEA_AUDIT_TOKEN` and
# `PANGEA_DOMAIN`.
token = os.getenv("PANGEA_AUDIT_TOKEN")
domain = os.getenv("PANGEA_DOMAIN")
config = PangeaConfig(domain=domain)

# Create a Secure Audit Log client.
audit = Audit(token, config)

# Log a basic event.
response = audit.log(message="Hello, World!")

asyncio support

asyncio support is available through the pangea.asyncio.services module. The previous example may be rewritten to utilize async/await syntax like so:

import asyncio
import os

from pangea.asyncio.services import AuditAsync
from pangea.config import PangeaConfig

# Load client configuration from environment variables `PANGEA_AUDIT_TOKEN` and
# `PANGEA_DOMAIN`.
token = os.getenv("PANGEA_AUDIT_TOKEN")
domain = os.getenv("PANGEA_DOMAIN")
config = PangeaConfig(domain=domain)

# Create a Secure Audit Log client.
audit = AuditAsync(token, config=config)


async def main():
    # Log a basic event.
    response = await audit.log(message="Hello, World!")

    await audit.close()


if __name__ == "__main__":
    asyncio.run(main())

Secure Audit Log - Integrity Tools

The Python Pangea SDK also includes some extra features to validate Audit Service log's integrity. Here we explain how to run them.

Verify audit data

Verify that an event or a list of events has not been tampered with. Usage:

usage: python -m pangea.verify_audit [-h] [--file PATH]
or
usage: poetry run python -m pangea.verify_audit [-h] [--file PATH]

Pangea Audit Verifier

options:
  -h, --help            show this help message and exit
  --file PATH, -f PATH  Input file (default: standard input).

It accepts multiple file formats:

  • a Verification Artifact from the Pangea User Console
  • a search response from the REST API:
$ curl -H "Authorization: Bearer ${PANGEA_TOKEN}" -X POST -H 'Content-Type: application/json'  --data '{"verbose": true}' https://audit.aws.us.pangea.cloud/v1/search

Bulk Download Audit Data

Download all audit logs for a given time range. Start and end date should be provided, a variety of formats is supported, including ISO-8601. The result is stored in a json file (one json per line).

usage: python -m pangea.dump_audit [-h] [--token TOKEN] [--domain DOMAIN] [--output OUTPUT] start end
or
usage: poetry run python -m pangea.dump_audit [-h] [--token TOKEN] [--domain DOMAIN] [--output OUTPUT] start end

Pangea Audit Dump Tool

positional arguments:
  start                 Start timestamp. Supports a variety of formats, including ISO-8601. e.g.: 2023-06-05T18:05:15.030667Z
  end                   End timestamp. Supports a variety of formats, including ISO-8601. e.g.: 2023-06-05T18:05:15.030667Z

options:
  -h, --help            show this help message and exit
  --token TOKEN, -t TOKEN
                        Pangea token (default: env PANGEA_TOKEN)
  --domain DOMAIN, -d DOMAIN
                        Pangea base domain (default: env PANGEA_DOMAIN)
  --output OUTPUT, -o OUTPUT
                        Output file name. Default: dump-<timestamp>

Perform Exhaustive Verification of Audit Data

This script performs extensive verification on a range of events of the log stream. Apart from verifying the hash and the membership proof, it checks that there are no omissions in the stream, i.e. all the events are present and properly located.

usage: python -m pangea.deep_verify [-h] [--token TOKEN] [--domain DOMAIN] --file FILE
or
usage: poetry run python -m pangea.deep_verify [-h] [--token TOKEN] [--domain DOMAIN] --file FILE

Pangea Audit Event Deep Verifier

options:
  -h, --help            show this help message and exit
  --token TOKEN, -t TOKEN
                        Pangea token (default: env PANGEA_TOKEN)
  --domain DOMAIN, -d DOMAIN
                        Pangea base domain (default: env PANGEA_DOMAIN)
  --file FILE, -f FILE  Event input file. Must be a collection of JSON Objects separated by newlines

It accepts multiple file formats:

  • a Verification Artifact from the Pangea User Console
  • a file generated by the dump_audit command
  • a search response from the REST API (see verify_audit)

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

pangea_sdk-5.1.0.tar.gz (122.4 kB view details)

Uploaded Source

Built Distribution

pangea_sdk-5.1.0-py3-none-any.whl (146.5 kB view details)

Uploaded Python 3

File details

Details for the file pangea_sdk-5.1.0.tar.gz.

File metadata

  • Download URL: pangea_sdk-5.1.0.tar.gz
  • Upload date:
  • Size: 122.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.9.20 Linux/6.1.100+

File hashes

Hashes for pangea_sdk-5.1.0.tar.gz
Algorithm Hash digest
SHA256 a1f4fb4ea5c64285c2a7bcddbe0e9abab91a3dfb263c15c8af783bea6749d7fb
MD5 4ed9032d061c4b5c23c90c9932197813
BLAKE2b-256 a3c4e1e57fd8c225f81c2f82ded4ac1ea0c7313bf1ffbfed95ae0061d2b5e4c8

See more details on using hashes here.

File details

Details for the file pangea_sdk-5.1.0-py3-none-any.whl.

File metadata

  • Download URL: pangea_sdk-5.1.0-py3-none-any.whl
  • Upload date:
  • Size: 146.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.9.20 Linux/6.1.100+

File hashes

Hashes for pangea_sdk-5.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 deac6d9df2768fe65b57cfe59b580780c3fff340d2a46b25ddbaff2d2fc41673
MD5 bbfba9e817ecebe3d156f2f5a5dbd8f4
BLAKE2b-256 ba823ca2ac0e7dd7bd63f7b1b32509db524eace1b3fb082a129e675614dc44ae

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page