diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e83f14..31c8f78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 506c2bd..ca99e73 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 7a55d9e..461ba70 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "cradl" -version = "0.4.5" +version = "0.4.6" description = "Python SDK for Cradl" authors = [{ name = "Cradl", email = "hello@cradl.ai" }] readme = "README.md" diff --git a/src/cradl/client.py b/src/cradl/client.py index 82ce44e..5b59485 100644 --- a/src/cradl/client.py +++ b/src/cradl/client.py @@ -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. @@ -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( @@ -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() @@ -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() @@ -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': '', 'action': 'read|write', 'effect': 'allow|deny'}] + >>> client.create_role(permissions, 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': '', 'action': 'read|write', 'effect': 'allow|deny'}] + >>> client.update_role('', permissions=permissions, 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. @@ -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('') + + :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.