Skip to main content


Pangea Logo


documentation Discord


Pangea Python SDK

A Python SDK for integrating with Pangea Services.

Setup

pip3 install pangea-sdk
# or
poetry add pangea-sdk

Usage

Secure Audit Service - Log Data

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

# Read your project domain from an env variable
domain = os.getenv("PANGEA_DOMAIN")

# Read your access token from an env variable
token = os.getenv("PANGEA_TOKEN")

# Create a Config object contain the Audit Config ID
config = PangeaConfig(domain=domain)

# Initialize an Audit instance using the config object
audit = Audit(token, config=config)

# Create test data
# All input fields are listed, only `message` is required
event = {
    "action": "reboot",
    "actor": "villan",
    "target": "world",
    "status": "error",
    "source": "test",
    "old" : "on",
    "new" : "restart",
    "message": "despicable act prevented",
}

response = audit.log(event)

print(response.result)

Secure Audit Service - Search Data

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

# Read your project domain from an env variable
domain = os.getenv("PANGEA_DOMAIN")

# Read your access token from an env variable
token = os.getenv("PANGEA_TOKEN")

# Create a Config object contain the Audit Config ID
config = PangeaConfig(domain=domain)

# Initialize an Audit instance using the config object
audit = Audit(token, config=config)

# Search for 'message' containing 'reboot'
# filtered on 'source=test', with 5 results per-page
response = audit.search(
        query="message:prevented",
        limit=5
    )

if response.success:
    print("Search Request ID:", response.request_id, "\n")

    print(
        f"Found {response.result.count} event(s)",
    )
    for row in response.result.events:
        print(f"{row.envelope.received_at}\taction: {row.envelope.event.actor}\taction: {row.envelope.event.action}\ttarget: {row.envelope.event.target}\tstatus: {row.envelope.event.status}\tmessage: {row.envelope.event.message}")

else:
    print("Search Failed:", response.code, response.status)

Secure Audit Service - Integrity Tools

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]

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 jsonl file (one json per line)

usage: 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
  end                   End timestamp. Supports a variety of formats, including ISO-8601

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. Appart from verifying the hash and the membership proof, it checks that there is 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

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)

Contributing

Currently, the setup scripts only have support for Mac/ZSH environments. Future support is incoming.

To install our linters, simply run ./dev/setup_repo.sh These linters will run on every git commit operation.

Generate SDK Documentation

Overview

Throughout the SDK, there are Python doc strings that serve as the source of our SDK docs.

The documentation pipeline here looks like:

  1. Write doc strings throughout your Python code. Please refer to existing doc strings as an example of what and how to document.
  2. Make your pull request.
  3. After the pull request is merged, go ahead and run the parse_module.py script to generate the JSON docs uses for rendering.
  4. Copy the output from parse_module.py and overwrite the existing python_sdk.json file in the docs repo. File is located in platform/docs/openapi/python_sdk.json in the Pangea monorepo. Save this and make a merge request to update the Python SDK docs in the Pangea monorepo.

Running the autogen sdk doc script

Make sure you have all the dependencies installed. From the root of the pangea-sdk package in the pangea-python repo run:

poetry install

Now run the script

poetry run python parse_module.py

That will output the script in the terminal. If you're on a mac, you can do

poetry run python parse_module.py | pbcopy

to copy the output from the script into your clipboard. At the moment, a bunch of stuff will be printed to the terminal if you pipe it to pbcopy, but the script still works and copies the output to your clipboard.

Release files for pangea-sdk 1.0.1

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

Source distribution (sdist)

Source distribution for pangea-sdk 1.0.1
File Size Uploaded
pangea_sdk-1.0.1.tar.gz 33.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pangea-sdk 1.0.1
File Interpreter ABI Platform
pangea_sdk-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 73.3 kB

Release files / pangea_sdk-1.0.1.tar.gz

Download URL pangea_sdk-1.0.1.tar.gz
Size 33.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a2264daaa4b876150218c3c8f02bf7a13b86947af312042a2e954803ce8db87b
BLAKE2b-256 checksum
How to use checksums
e9647e7ce2dd145528fac133775637fca8708691cc78afd0a6358fe1abe51c7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.7.16 Linux/5.10.0-18-cloud-arm64

Release files / pangea_sdk-1.0.1-py3-none-any.whl

Download URL pangea_sdk-1.0.1-py3-none-any.whl
Size 39.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c55ceb457f82b35ad7e294cc18c464f7e9c940bdc4dbf5205558f54b5137075f
BLAKE2b-256 checksum
How to use checksums
cea84d2654fde18b116c87190a08c3ac9369fe287e5b50b641ed29fdc1bd8324
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.7.16 Linux/5.10.0-18-cloud-arm64

Release history Release notifications | RSS feed

6.13.0

2 release files

6.12.0

2 release files

6.10.0

2 release files

6.9.0

2 release files

6.8.0

2 release files

6.7.0

2 release files

6.6.0

2 release files

6.5.0

2 release files

6.4.0

2 release files

6.3.0

2 release files

6.2.0

2 release files

6.1.1

2 release files

6.1.0

2 release files

6.0.0

2 release files

5.5.1

2 release files

5.5.0

2 release files

5.4.0

2 release files

5.3.0

2 release files

5.2.1

2 release files

5.2.0

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.4.0

2 release files

4.3.0

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.9.0

2 release files

3.8.0

2 release files

3.7.1

2 release files

3.7.0

2 release files

3.6.1

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.10.0

2 release files

1.9.1

2 release files

1.9.0

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.4.0

2 release files

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