Skip to main content

GroundX Python Library

fern shield pypi

The GroundX Python library provides convenient access to the GroundX API from Python.

Documentation

API reference documentation is available here.

Installation

pip install groundx

Reference

A full reference for this library is available here.

Usage

Instantiate and use the client with the following:

from groundx import Document, GroundX

client = GroundX(
    api_key="YOUR_API_KEY",
)

client.ingest(
    documents=[
        Document(
            bucket_id=1234,
            file_name="my_file1.txt",
            file_type="txt",
            source_url="https://my.source.url.com/file1.txt",
        )
    ],
)

Extraction Workflows

Create or update an extraction workflow directly from a YAML file:

from groundx import GroundX

client = GroundX(api_key="YOUR_API_KEY")

workflow = client.create_extraction_workflow(
    path="statement.yaml",
    name="statement extraction",
)

client.update_extraction_workflow(
    workflow.workflow.workflow_id,
    path="statement.yaml",
    name="statement extraction",
)

The SDK sends the YAML unchanged. GroundX validates and compiles it.

Server workflow metadata readback requires the extract extra:

pip install "groundx[extract]"

Load an existing workflow when you need its compiled extraction metadata:

existing = client.load_extraction_definition_from_workflow("workflow-id")

For create and update, pass exactly one of path=... or yaml_text=.... Compiled definitions, mappings, and prepared objects are not authoring inputs.

Workflow assignment is still explicit. After creating a workflow, assign it to a bucket, group, or account with the normal workflow API.

Async Client

The SDK also exports an async client so that you can make non-blocking calls to our API.

import asyncio

from groundx import AsyncGroundX, Document

client = AsyncGroundX(
    api_key="YOUR_API_KEY",
)

async def main() -> None:
    await client.ingest(
        documents=[
            Document(
                bucket_id=1234,
                file_name="my_file1.txt",
                file_type="txt",
                source_url="https://my.source.url.com/file1.txt",
            )
        ],
    )

asyncio.run(main())

Exception Handling

When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error will be thrown.

from groundx.core.api_error import ApiError

try:
    client.ingest(...)
except ApiError as e:
    print(e.status_code)
    print(e.body)

Advanced

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retriable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retriable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the max_retries request option to configure this behavior.

client.ingest(..., request_options={
    "max_retries": 1
})

Timeouts

The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.

from groundx import GroundX

client = GroundX(
    ...,
    timeout=20.0,
)


# Override timeout for a specific method
client.ingest(..., request_options={
    "timeout_in_seconds": 1
})

Custom Client

You can override the httpx client to customize it for your use-case. Some common use-cases include support for proxies and transports.

import httpx
from groundx import GroundX

client = GroundX(
    ...,
    httpx_client=httpx.Client(
        proxies="http://my.test.proxy.example.com",
        transport=httpx.HTTPTransport(local_address="0.0.0.0"),
    ),
)

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

Protected files

Requires a compatible SDK and an API deployment with file access enabled. Source schemas or generated methods alone do not establish deployment availability.

import os
from groundx import GroundX, Document, FileAccessPolicy

client = GroundX(api_key=os.environ["GROUNDX_API_KEY"])
bucket = client.buckets.create(
    name="private-documents",
    file_access=FileAccessPolicy(mode="protected"),
)
client.ingest(documents=[Document(
    bucket_id=bucket.bucket.bucket_id,
    file_path="./contract.pdf",
    file_access=FileAccessPolicy(mode="protected", url_ttl_seconds=120),
)])

Initial policies are optional; omitted/null inherits account/bucket settings. The sync and async ingest helpers request upload URLs from the configured GroundX API for every local file, public or protected. On-prem uploads use that installation's storage and do not contact the hosted upload service. A failed upload request stops ingestion without a public fallback. Each initial file policy is checked by upload admission before bytes are sent. Directory ingest accepts file_access for every file in that call.

Upload grants allow PUT for at most fifteen minutes. They do not expire an already uploaded public file or prevent its later ingestion. Protected source reservations must reach ingest before their deadline; the API rejects expired reservations. Retry those files with a smaller batch. The helpers check each grant before PUT and return ingest errors without renewing or splitting a batch.

Deploy the bucket upload endpoint before adopting these helpers. Existing integrations can explicitly set upload_api to keep the legacy broker protocol for public files. An override is rejected for inherited or requested protection.

Later policy changes require the current revision. Stable protected URLs need current API authentication and have no age-based expiry. documents.file_link issues a finite bearer link that can be forwarded until expiry; later key/policy changes do not revoke it. Keep native signatures intact and API keys server-side. Fern owns the human API guide. The Studio Harness API/MCP file-access references cover asset selectors, private upload, refresh and on-prem use.

Metadata

Release files for groundx 4.1.8

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

Source distribution (sdist)

Source distribution for groundx 4.1.8
File Size Uploaded Provenance Actions
groundx-4.1.8.tar.gz 180.4 kB Without provenance Details for groundx-4.1.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for groundx 4.1.8
File Interpreter ABI Platform Actions
groundx-4.1.8-py3-none-any.whl Python 3 none any Details for groundx-4.1.8-py3-none-any.whl

Total release size: 454.8 kB

Release files / groundx-4.1.8.tar.gz

Download URL groundx-4.1.8.tar.gz
Size 180.4 kB
Tags Source
SHA-256 checksum
How to use checksums
712389ffd3ff233ceb82aa5506175b86caccedc045e55c7f2f108a2dce71b383
BLAKE2b-256 checksum
How to use checksums
110488ef22748e1ed2ca6299adf6939dd3fb8ebbb3af77f89eeedc8224abae6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.22 Linux/7.0.0-1017-azure

Release files / groundx-4.1.8-py3-none-any.whl

Download URL groundx-4.1.8-py3-none-any.whl
Size 274.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
74da1d358209ad8d41f898529a3799dc1d4d77bbf504f10c770f1453c14e256a
BLAKE2b-256 checksum
How to use checksums
c76c3adcf207e01b78937e6e176578ba95efc9745924450bf6410cc590b36c4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.22 Linux/7.0.0-1017-azure

Security for groundx 4.1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

4.1.8 This release

2 release files No provenance

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