GroundX Python Library
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:
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!
Release files for groundx 4.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| groundx-4.0.6.tar.gz | 164.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| groundx-4.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:414.1 kB
Release files / groundx-4.0.6.tar.gz
| Download URL | groundx-4.0.6.tar.gz |
|---|---|
| Size | 164.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c533d83bd25e8a0ed63bcdee242d86eb4ebd4c328f2120f4706963920c16aad0
|
|
BLAKE2b-256 checksum How to use checksums |
0d53165336086734867686b0f7b8078fcdcca90bcef6f5fb3d16aeac01f75b21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.10.21 Linux/6.17.0-1022-azure
|
Release files / groundx-4.0.6-py3-none-any.whl
| Download URL | groundx-4.0.6-py3-none-any.whl |
|---|---|
| Size | 249.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f528c0e010f9355b73885e281b96c7ce60ca1a59676e740d8c2c41f26e89fdb0
|
|
BLAKE2b-256 checksum How to use checksums |
05c2bfe9f85ac17cb2ac20f27560e5cc8daf916cb1a553db9b9ec8e282ae9dfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.10.21 Linux/6.17.0-1022-azure
|