Python Client for interacting with HAL-forms application
Project description
HALFormsClient Library
Overview
The HALFormsClient library provides a Python client for interacting with RESTful services that use the HAL (Hypertext Application Language) and HAL-Forms standards. This library simplifies the handling of HAL responses and their embedded resources, enabling easy navigation and interaction with APIs that follow the HAL and HAL-Forms specifications.
Features
- Automatic token management for service accounts.
- Robust retry mechanisms for HTTP requests.
- Easy navigation of HAL links and embedded resources.
- Support for CURIEs (Compact URIs) for compacting and expanding link relations.
- Handling of common HTTP methods (
GET,POST,PATCH,DELETE,PUT) with ease. - Validation and transformation of HAL links and URIs.
- Customizable client configuration, including endpoint and authentication details.
Installation
To install the library, use pip:
pip install contentgrid-hal-client
Usage
Initialization
To initialize the HALFormsClient, you need to provide the endpoint of the HAL service and optionally authentication details:
from halformsclient import HALFormsClient
# Initialize using service account
client = HALFormsClient(
client_endpoint="https://api.example.com",
auth_uri="https://auth.example.com",
client_id="your_client_id",
client_secret="your_client_secret",
)
# Initialize using bearer token
client = HALFormsClient(
client_endpoint="https://api.example.com",
auth_uri="https://auth.example.com",
token="your_token"
)
# Initialize using session cookie
client = HALFormsClient(
client_endpoint="https://api.example.com",
auth_uri="https://auth.example.com",
session_cookie="your_session_cookie"
)
Fetching and Interacting with HAL Resources
You can fetch a HAL resource and interact with it using the provided methods:
# Fetch a resource by following a link
resource = client.follow_link(HALLink(uri="/some/resource"))
# Access metadata
print(resource.metadata)
# Access links
links = resource.get_links("key")
# Access embedded resources
embedded_objects = resource.get_embedded_objects_by_key("embedded_key")
# Update a resource with PUT or PATCH
resource.put_data({"key": "value"})
resource.patch_data({"key": "new_value"})
# Delete a resource
resource.delete()
Handling CURIEs
CURIEs (Compact URIs) are supported for compacting and expanding link relations:
curie_registry = CurieRegistry(curies=[{"name": "ex", "href": "https://example.com/{rel}"}])
expanded_uri = curie_registry.expand_curie("ex:some_relation")
compact_uri = curie_registry.compact_curie("https://example.com/some_relation")
Error Handling
The library provides custom exceptions for common HTTP errors:
from halformsclient.exceptions import BadRequest, Unauthorized
try:
resource = client.follow_link(HALLink(uri="/some/invalid/resource"))
except BadRequest as e:
print(f"Bad request: {str(e)}")
except Unauthorized as e:
print(f"Unauthorized: {str(e)}")
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 contentgrid_hal_client-0.2.0.tar.gz.
File metadata
- Download URL: contentgrid_hal_client-0.2.0.tar.gz
- Upload date:
- Size: 25.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f51b836c4f1c8a0b356c10f1814fb9c6bebfa819d6a71c81c1e978ff5a5c45e
|
|
| MD5 |
862e969d6b7645b4d5866923c0bc3e73
|
|
| BLAKE2b-256 |
7e1ffd2cdf6b50335b61f50f21ea386d99ae024c1eb3f47e91fa893f21f4cb3d
|
Provenance
The following attestation bundles were made for contentgrid_hal_client-0.2.0.tar.gz:
Publisher:
publish.yml on xenit-eu/contentgrid-python-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
contentgrid_hal_client-0.2.0.tar.gz -
Subject digest:
7f51b836c4f1c8a0b356c10f1814fb9c6bebfa819d6a71c81c1e978ff5a5c45e - Sigstore transparency entry: 749199138
- Sigstore integration time:
-
Permalink:
xenit-eu/contentgrid-python-client@0e38a4ea01f9b85178635c9360179986ef8aafe6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/xenit-eu
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0e38a4ea01f9b85178635c9360179986ef8aafe6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file contentgrid_hal_client-0.2.0-py3-none-any.whl.
File metadata
- Download URL: contentgrid_hal_client-0.2.0-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3076d8d419a03b10a3e3d0316530eff10f1beadb5f3ce746d0d1c1bd52211e7f
|
|
| MD5 |
b110308f23c7e315a1320bf447872b70
|
|
| BLAKE2b-256 |
2ca69cf4dde26d4802c7814447e0b21fc912023ed30f6e447da6e88303d616d6
|
Provenance
The following attestation bundles were made for contentgrid_hal_client-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on xenit-eu/contentgrid-python-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
contentgrid_hal_client-0.2.0-py3-none-any.whl -
Subject digest:
3076d8d419a03b10a3e3d0316530eff10f1beadb5f3ce746d0d1c1bd52211e7f - Sigstore transparency entry: 749199170
- Sigstore integration time:
-
Permalink:
xenit-eu/contentgrid-python-client@0e38a4ea01f9b85178635c9360179986ef8aafe6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/xenit-eu
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0e38a4ea01f9b85178635c9360179986ef8aafe6 -
Trigger Event:
release
-
Statement type: