Skip to main content

BetterCollected Python SDK and CLI

A small typed client for the BetterCollected public API (httpx and Pydantic), and the bettercollected command line tool for keeping forms as code. The models are generated from the form spec JSON Schema and the API's OpenAPI document.

Works with bettercollected 4.1 or later, on bettercollected.com or on your own instance. Python 3.10 or later.

Install

pip install bettercollected

or uv add bettercollected. This installs the library and the bettercollected command.

API key

A workspace admin creates an API key on the dashboard's AI → MCP tab (/<workspace>/dashboard/ai/mcp). A key works in its own workspace only and never does more than the person who created it may do. Keep it out of your code and pass it in through the environment.

Quick start

import os
from bettercollected import BetterCollected, BetterCollectedError

with BetterCollected(os.environ["BETTERCOLLECTED_API_KEY"], "https://forms.example.org") as bc:
    created = bc.create_form({"specVersion": "1", "title": "Sign-up", "pages": [{"id": "p1", "fields": []}]}, idempotency_key="signup-v1")
    ops = [{"op": "add_field", "pageId": "p1", "field": {"title": "Your email", "type": "email", "required": True}}]
    result = bc.apply_ops(created.form_id, ops, if_match=created.etag)
    try:
        bc.publish_form(created.form_id)
    except BetterCollectedError as error:
        print(error.code, [(e.path, e.message) for e in error.errors])

The second argument is the address of your instance. Reads that return a version give Versioned(value, etag); pass the etag as if_match to change exactly that version.

Forms as code (CLI)

JSON is the canonical format; YAML (.yaml, .yml) works too. The API key is read from BETTERCOLLECTED_API_KEY only; the instance from --url or BETTERCOLLECTED_URL.

export BETTERCOLLECTED_URL=https://forms.example.org
export BETTERCOLLECTED_API_KEY=bc_...

bettercollected pull 6123abc... -o signup.json   # write the form to a file
bettercollected validate signup.json             # check it (exit 1 when invalid)
bettercollected diff signup.json                 # what push would change
bettercollected push signup.json                 # replace the form
bettercollected push signup.json --force         # overwrite changes made since the pull

pull records the form id and version in .bettercollected.json next to the file (no secrets). push replaces the form only while it is still that version, and refuses otherwise; --force fetches the current version first.

Development

From sdk/python in the repository:

uv sync
uv run pytest
uv run python scripts/generate.py   # after docs/spec or docs/api changed
uv build                            # dist/

Lock with uvx uv@0.12.23 lock. Releases are published from CI; see "SDK releases" in RELEASING.md.

Licence

Apache-2.0. See LICENSE.

Metadata

Release files for bettercollected 0.1.0

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

Source distribution (sdist)

Source distribution for bettercollected 0.1.0
File Size Uploaded Provenance Actions
bettercollected-0.1.0.tar.gz 19.4 kB With provenance Details for bettercollected-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 41.4 kB

Release files / bettercollected-0.1.0.tar.gz

Download URL bettercollected-0.1.0.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9d479e9ba8a9fd057029fb13447100d3f8e86767b247742048d711d056305f15
BLAKE2b-256 checksum
How to use checksums
22767c23270903f022f972103fe9d6597873b3367201c1cf617ba20c57b6caed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Release files / bettercollected-0.1.0-py3-none-any.whl

Download URL bettercollected-0.1.0-py3-none-any.whl
Size 22.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c802f33ebafba533cecef3d0cf02047e19f4666d530b51194af2028327f0abd5
BLAKE2b-256 checksum
How to use checksums
5276d15dc61b758055733712a75d6897a894f6016522331abbd959851d17c8b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Security for bettercollected 0.1.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bettercollected-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

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

0.1.0 This release

2 release files Full 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