Python SDK Documents

Upload, presign and download documents with the planned Python SDK.

The SDK exposes generic document methods through client.documents, plus feature-owned helpers that reduce mistakes around entityType, entityId and category.

Prefer feature-owned helpers when they exist.

Supplier document upload

Python
from pathlib import Path
client = ConformaClient.from_env()
document = client.suppliers.upload_document(
supplier_id="3f2b9a1c-4d2e-4b6e-9c1a-6f5b8e2d7c10",
file=Path("supplier-profile.pdf"),
)

For supplier certification files:

Python
document = client.suppliers.certifications.attach_document(
id="supplier-certification-uuid",
file=Path("gots-certificate.pdf"),
)

See Supplier Documents.

Purchase invoice upload

Python
from pathlib import Path
document = client.purchases.documents.upload(
purchase_id="purchase-uuid",
category="INVOICE",
file=Path("invoice.pdf"),
)

See Purchase Documents.

Streaming download

Python
from pathlib import Path
client.documents.download(
id="document-uuid",
destination=Path("downloads/invoice.pdf"),
)

When destination is provided, the SDK should stream to disk instead of loading the whole file in memory. If no destination is provided, the planned return value is bytes.

Generic presigned upload

Python
from conformaesg.models import PresignUploadRequest, CompleteUploadRequest
upload = client.documents.presign(
PresignUploadRequest(
entity_type="SUPPLIER",
entity_id="3f2b9a1c-4d2e-4b6e-9c1a-6f5b8e2d7c10",
category="POLICY",
file_name="supplier-policy.pdf",
content_type="application/pdf",
size_bytes=1048576,
)
)
client.documents.upload_to_presigned_url(
upload.presigned_url,
file=Path("supplier-policy.pdf"),
content_type="application/pdf",
)
document = client.documents.complete(
upload.document_id,
CompleteUploadRequest(checksum_sha256="64-character-sha256-hex"),
)

Use Documents for generic metadata, presign, complete, download and delete behavior.

File input rules

Planned SDK file helpers accept:

  • pathlib.Path
  • file-like objects
  • bytes with an explicit filename

The SDK should close only files that it opened itself. It should validate file existence, content type and size where possible before sending the request.