Skip to main content

No project description provided

Project description

Pangram Labs Python Package

Installation

pip install pangram-sdk

Add your API key

Add your API key as an environment variable, or pass it directly to the Pangram constructor.

export PANGRAM_API_KEY=<your API key>
from pangram import Pangram
# If the environment variable PANGRAM_API_KEY is set:
pangram_client = Pangram()

# Otherwise, pass the API key directly:
my_api_key = ''  # Fill this in with your API key.
pangram_client = Pangram(api_key=my_api_key)

Make a request

Main prediction method (AI-assistance detection and segment-level analysis):

from pangram import Pangram
pangram_client = Pangram()

result = pangram_client.predict(text)
stage = result['stage']  # "STAGE_SUCCESS" after predict() completes.

# Analysis with AI-assistance detection.
fraction_ai = result['fraction_ai']
fraction_ai_assisted = result['fraction_ai_assisted']
fraction_human = result['fraction_human']
num_ai_segments = result['num_ai_segments']

# Access individual window classifications
for window in result['windows']:
    label = window['label']  # e.g., "AI-Generated", "Moderately AI-Assisted"
    ai_assistance_score = window['ai_assistance_score']
    confidence = window['confidence']  # "High", "Medium", "Low"

predict() submits to Pangram's async inference API and waits for the result before returning. Use predict(text, public_dashboard_link=True) or predict_with_dashboard_link(text, timeout=300, poll_interval=0.5) to include a dashboard_link in the completed result.

Submit a Bulk API job

Use the Bulk API for asynchronous AI detection across many inputs. Submit either a list of strings with text or a list of objects with items. Item id values are optional customer IDs that are returned with item status and results.

Bulk jobs are processed asynchronously. Completion time depends on the number and length of submitted items and current system load. Use get_bulk_status() or wait_for_bulk() to monitor progress.

from pangram import Pangram

pangram_client = Pangram()

bulk = pangram_client.submit_bulk(items=[
    {"id": "row-001", "text": "First text to analyze"},
    {"id": "row-002", "text": "Second text to analyze"},
])

bulk_id = bulk["bulk_id"]
status = pangram_client.wait_for_bulk(bulk_id, poll_interval=2)
results = pangram_client.get_bulk_results(bulk_id)

for item in results["items"]:
    if item["result"] is not None:
        print(item["id"], item["result"]["prediction_short"])

for failed in results["failed_items"]:
    print(failed["id"], failed["error"])

Bulk jobs can also be inspected without waiting:

status = pangram_client.get_bulk_status(bulk_id)
items = pangram_client.get_bulk_items(bulk_id, offset=0, limit=100)
results_page = pangram_client.get_bulk_results_page(bulk_id, offset=0, limit=100)

For large jobs, use get_bulk_results_page() in a loop instead of get_bulk_results() to process one page at a time without holding the full result set in memory:

offset = 0
limit = 1000

while True:
    page = pangram_client.get_bulk_results_page(bulk_id, offset=offset, limit=limit)
    for item in page["items"]:
        process(item)
    for failed in page["failed_items"]:
        handle_failure(failed)

    offset += limit
    if offset >= page["total_items"]:
        break

Building Documentation

Install docs dependencies and build:

poetry install --with docs
cd docs && make html

Questions? Email support@pangram.com!

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

pangram_sdk-0.3.0.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.

pangram_sdk-0.3.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file pangram_sdk-0.3.0.tar.gz.

File metadata

  • Download URL: pangram_sdk-0.3.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pangram_sdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f83dbbd49c42975f0e25d456cc344395ec19f3d918ea71dbc50d75818e1ea32d
MD5 e2568a2e85d2a4919c52088c8b5ec003
BLAKE2b-256 63fdb7154aa8f12fe8e3b8584e3848110ad581eec0cc9c9acd0855ae5eec2527

See more details on using hashes here.

Provenance

The following attestation bundles were made for pangram_sdk-0.3.0.tar.gz:

Publisher: publish-to-pypi.yml on pangramlabs/pangram-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pangram_sdk-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pangram_sdk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pangram_sdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c49f6876239e46b146e82fb277d03ee65961a986ff5a02a6f6c8e13a2e65c24
MD5 a7f9dd74109eb11ad763a3b752f32375
BLAKE2b-256 ff6134b55b2449fe4936fa018adbcc5b9b3760158878409829d271bb040880f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pangram_sdk-0.3.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on pangramlabs/pangram-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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