Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Version 0.4.6 - 2025-10-17

- Add documentRetentionInDays to update_organization
- Add methods create_role, update_role and delete_role

## Version 0.4.2 - 2025-08-14

- Do not discard documents based on their content type
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $ pip install cradl
## Usage

Sign up for free [here](https://app.cradl.ai/signup) and download API credentials to use this SDK.
Read more about authenticating to the API [here](https://docs.cradl.ai/overview/authentication)
Read more about authenticating to the API [here](https://docs.cradl.ai/api-reference/introduction#authentication)

### Quick start

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "cradl"
version = "0.4.5"
version = "0.4.6"
description = "Python SDK for Cradl"
authors = [{ name = "Cradl", email = "[email protected]" }]
readme = "README.md"
Expand Down
78 changes: 76 additions & 2 deletions src/cradl/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,7 @@ def update_organization(
organization_id: str,
*,
payment_method_id: str = None,
document_retention_in_days: int = None,
**optional_args,
) -> Dict:
"""Updates an organization, calls the PATCH /organizations/{organizationId} endpoint.
Expand All @@ -1397,6 +1398,9 @@ def update_organization(
if payment_method_id:
body['paymentMethodId'] = payment_method_id

if document_retention_in_days:
body['documentRetentionInDays'] = document_retention_in_days

return self._make_request(requests.patch, f'/organizations/{organization_id}', body=body)

def create_prediction(
Expand Down Expand Up @@ -1627,7 +1631,7 @@ def list_deployment_environments(
return self._make_request(requests.get, '/deploymentEnvironments', params=dictstrip(params))

def create_secret(self, data: dict, **optional_args) -> Dict:
"""Creates an secret, calls the POST /secrets endpoint.
"""Creates a secret, calls the POST /secrets endpoint.

>>> from cradl.client import Client
>>> client = Client()
Expand Down Expand Up @@ -1676,7 +1680,7 @@ def list_secrets(self, *, max_results: Optional[int] = None, next_token: Optiona
return self._make_request(requests.get, '/secrets', params=params)

def update_secret(self, secret_id: str, *, data: Optional[dict] = None, **optional_args) -> Dict:
"""Updates an secret, calls the PATCH /secrets/secretId endpoint.
"""Updates a secret, calls the PATCH /secrets/secretId endpoint.

>>> from cradl.client import Client
>>> client = Client()
Expand Down Expand Up @@ -2478,6 +2482,59 @@ def delete_workflow_execution(self, workflow_id: str, execution_id: str) -> Dict
"""
return self._make_request(requests.delete, f'/workflows/{workflow_id}/executions/{execution_id}')

def create_role(self, permissions: List[Dict], **optional_args) -> Dict:
"""Creates a role, calls the POST /roles endpoint.

>>> from cradl.client import Client
>>> client = Client()
>>> permissions = [{'resource': '<resource-identifier>', 'action': 'read|write', 'effect': 'allow|deny'}]
>>> client.create_role(permissions, description='<description>')

:param permissions: List of permissions the role will have
:type permissions: list
:param name: Name of the role
:type name: str, optional
:param description: Description of the role
:type description: str, optional
:return: Role response from REST API
:rtype: dict

:raises: :py:class:`~cradl.InvalidCredentialsException`, :py:class:`~cradl.TooManyRequestsException`,\
:py:class:`~cradl.LimitExceededException`, :py:class:`requests.exception.RequestException`
"""
body = {
'permissions': permissions,
**optional_args,
}
return self._make_request(requests.post, '/roles', body=body)

def update_role(self, role_id: str, *, permissions: Optional[List[Dict]] = None, **optional_args) -> Dict:
"""Updates a role, calls the PATCH /roles/{roleId} endpoint.

>>> from cradl.client import Client
>>> client = Client()
>>> permissions = [{'resource': '<resource-identifier>', 'action': 'read|write', 'effect': 'allow|deny'}]
>>> client.update_role('<role id>', permissions=permissions, description='<description>')

:param role_id: Id of the role
:type role_id: str
:param permissions: List of permissions the role will have
:type permissions: list
:param name: Name of the role
:type name: str, optional
:param description: Description of the role
:type description: str, optional
:return: Role response from REST API
:rtype: dict

:raises: :py:class:`~cradl.InvalidCredentialsException`, :py:class:`~cradl.TooManyRequestsException`,\
:py:class:`~cradl.LimitExceededException`, :py:class:`requests.exception.RequestException`
"""
body = dictstrip({'permissions': permissions})
body.update(**optional_args)
return self._make_request(requests.patch, f'/roles/{role_id}', body=body)


def list_roles(self, *, max_results: Optional[int] = None, next_token: Optional[str] = None) -> Dict:
"""List roles available, calls the GET /roles endpoint.

Expand Down Expand Up @@ -2510,6 +2567,23 @@ def get_role(self, role_id: str) -> Dict:
"""
return self._make_request(requests.get, f'/roles/{role_id}')

def delete_role(self, role_id: str) -> Dict:
"""Delete the role with the provided role_id, calls the DELETE /roles/{roleId} endpoint.

>>> from cradl.client import Client
>>> client = Client()
>>> client.delete_role('<role_id>')

:param role_id: Id of the role
:type role_id: str
:return: Role response from REST API
:rtype: dict

:raises: :py:class:`~cradl.InvalidCredentialsException`, :py:class:`~cradl.TooManyRequestsException`,\
:py:class:`~cradl.LimitExceededException`, :py:class:`requests.exception.RequestException`
"""
return self._make_request(requests.delete, f'/roles/{role_id}')

def get_validation(self, validation_id: str) -> Dict:
"""Get validation, calls the GET /validations/{validationId} endpoint.

Expand Down
Loading