Python SDK for the CommonGrants protocol
Project description
CommonGrants Python SDK
A Python SDK for interacting with the CommonGrants protocol, providing a type-safe interface for managing grant opportunities.
Table of contents
Installation
# Using pip
pip install common-grants-sdk
# Using Poetry
poetry add common-grants-sdk
Usage
Quick start
from common_grants_sdk.client import Client, Auth
from common_grants_sdk.client.config import Config
# 1. Create a client
config = Config(base_url="https://api.example.org", api_key="YOUR_API_KEY")
client = Client(config=config, auth=Auth.api_key("YOUR_API_KEY"))
# 2. List opportunities
response = client.opportunities.list()
for opp in response.items:
print(f"{opp.title} ({opp.status.value})")
Kitchen sink example
This example shows how the SDK's modules work together: fetching data with the client, validating it with schemas, and accessing typed custom fields via extensions.
from common_grants_sdk.client import Client, Auth
from common_grants_sdk.client.config import Config
from common_grants_sdk.schemas.pydantic import (
OpportunityBase,
OppStatusOptions,
CustomFieldType,
)
from common_grants_sdk.extensions.specs import CustomFieldSpec
# Extend the base schema with custom fields
CustomOpportunity = OpportunityBase.with_custom_fields(
custom_fields={
"programArea": CustomFieldSpec(
field_type=CustomFieldType.STRING,
description="Grant program area",
),
"legacyId": CustomFieldSpec(
field_type=CustomFieldType.INTEGER,
description="Legacy system ID",
),
},
model_name="CustomOpportunity",
)
# Create a client
config = Config(base_url="https://api.example.org", api_key="YOUR_API_KEY")
client = Client(config=config, auth=Auth.api_key("YOUR_API_KEY"))
# Fetch opportunities using the extended schema
response = client.opportunities.list(schema=CustomOpportunity)
for opp in response.items:
print(f"{opp.title} ({opp.status.value})")
# Access typed custom fields
if opp.status.value == OppStatusOptions.OPEN:
program = opp.get_custom_field_value("programArea", str)
print(f" Program area: {program}")
# Validate standalone data directly against the schema
raw = {
"id": "ac201443-5480-4e36-9799-a39765225153",
"title": "Community Health Grant",
"description": "A grant supporting community health initiatives.",
"status": {"value": "open"},
"createdAt": "2025-01-01T00:00:00Z",
"lastModifiedAt": "2025-01-01T00:00:00Z",
}
validated_opp = OpportunityBase.model_validate(raw)
print(validated_opp.title)
Modules
The SDK is organized into modules, each with its own documentation:
| Module | Description |
|---|---|
| Client | HTTP client with auth, pagination, and low-level HTTP methods |
| Schemas | Pydantic models, validation, and generic response schemas |
| Extensions | Custom fields and plugin framework |
API Client
HTTP client with built-in authentication, auto-pagination, and environment variable configuration. See the Client guide for setup, authentication, and usage examples.
Schemas and Validation
Pydantic v2 models for validating and parsing CommonGrants data, along with type-safe enum constants. See the Schemas guide for validation examples, type safety patterns, and the full API reference.
Extensions and Plugins
Extension framework for adding typed custom fields to CommonGrants schemas, either ad hoc or as reusable plugins. See the Extensions guide for the full guide.
License
See LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file common_grants_sdk-0.7.0.tar.gz.
File metadata
- Download URL: common_grants_sdk-0.7.0.tar.gz
- Upload date:
- Size: 42.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Linux/6.17.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31695f0a41d54aedb7b883c2ef711de8d8e1c3a486f03511c72ea234432dad58
|
|
| MD5 |
6cf2a984ed1cd6a9b337dfb10f3440f9
|
|
| BLAKE2b-256 |
28ab14498c32bdd065a43b13e2ee11b3f0fdbe275eacd695bcc74b5db9a47e32
|
File details
Details for the file common_grants_sdk-0.7.0-py3-none-any.whl.
File metadata
- Download URL: common_grants_sdk-0.7.0-py3-none-any.whl
- Upload date:
- Size: 64.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Linux/6.17.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26852c8f560302379b286c944c0b973658262660c9996c628b4556665ecef718
|
|
| MD5 |
b5eec3cd44ba8c30e406c018cbce7441
|
|
| BLAKE2b-256 |
bf3b65b839f53001daf6b53de73acac291c4666de54ca0aab90536e60ac2c4dd
|