capo-redshift-data 0.12.0__tar.gz → 0.14.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. {capo_redshift_data-0.12.0/src/capo_redshift_data.egg-info → capo_redshift_data-0.14.0}/PKG-INFO +3 -1
  2. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/README.md +2 -0
  3. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/pyproject.toml +1 -1
  4. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_auth/_sigv4.py +5 -2
  5. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_services/_aws_config.py +15 -0
  6. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_services/_pipeline.py +207 -0
  7. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_services/async_redshift_data.py +12 -1
  8. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_services/redshift_data.py +12 -1
  9. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0/src/capo_redshift_data.egg-info}/PKG-INFO +3 -1
  10. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/tests/test_sigv4.py +33 -0
  11. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/LICENSE +0 -0
  12. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/setup.cfg +0 -0
  13. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/__init__.py +0 -0
  14. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_async.py +0 -0
  15. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_auth/_identity.py +0 -0
  16. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_auth/_providers.py +0 -0
  17. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_auth/_signers.py +0 -0
  18. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_auth/_zapros_handler.py +0 -0
  19. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_aws.py +0 -0
  20. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_body.py +0 -0
  21. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_iter.py +0 -0
  22. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_operations/redshift_data/batch_execute_statement.py +0 -0
  23. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_operations/redshift_data/cancel_statement.py +0 -0
  24. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_operations/redshift_data/describe_statement.py +0 -0
  25. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_operations/redshift_data/describe_table.py +0 -0
  26. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_operations/redshift_data/execute_statement.py +0 -0
  27. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_operations/redshift_data/get_statement_result.py +0 -0
  28. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_operations/redshift_data/get_statement_result_v2.py +0 -0
  29. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_operations/redshift_data/list_databases.py +0 -0
  30. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_operations/redshift_data/list_schemas.py +0 -0
  31. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_operations/redshift_data/list_sessions.py +0 -0
  32. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_operations/redshift_data/list_statements.py +0 -0
  33. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_operations/redshift_data/list_tables.py +0 -0
  34. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_pagination.py +0 -0
  35. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_protocol/__init__.py +0 -0
  36. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_protocol/errors.py +0 -0
  37. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_protocol/eventstream.py +0 -0
  38. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_protocol/serialize.py +0 -0
  39. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_protocol/xml.py +0 -0
  40. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_rule_engine/__init__.py +0 -0
  41. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_rule_engine/_aws_partition.py +0 -0
  42. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_rule_engine/_endpoint_rule_set.py +0 -0
  43. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/_rule_engine/_endpoint_runtime.py +0 -0
  44. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/errors/__init__.py +0 -0
  45. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/errors/_base.py +0 -0
  46. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/errors/active_sessions_exceeded_exception.py +0 -0
  47. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/errors/active_statements_exceeded_exception.py +0 -0
  48. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/errors/active_waiting_requests_exceeded_exception.py +0 -0
  49. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/errors/batch_execute_statement_exception.py +0 -0
  50. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/errors/database_connection_exception.py +0 -0
  51. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/errors/execute_statement_exception.py +0 -0
  52. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/errors/internal_server_exception.py +0 -0
  53. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/errors/query_timeout_exception.py +0 -0
  54. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/errors/resource_not_found_exception.py +0 -0
  55. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/errors/validation_exception.py +0 -0
  56. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/py.typed +0 -0
  57. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/_prelude/blob.py +0 -0
  58. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/_prelude/timestamp.py +0 -0
  59. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/_unknown.py +0 -0
  60. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/batch_execute_statement_input.py +0 -0
  61. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/batch_execute_statement_output.py +0 -0
  62. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/blob.py +0 -0
  63. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/bool.py +0 -0
  64. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/boxed_boolean.py +0 -0
  65. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/boxed_double.py +0 -0
  66. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/boxed_long.py +0 -0
  67. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/cancel_statement_request.py +0 -0
  68. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/cancel_statement_response.py +0 -0
  69. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/client_token.py +0 -0
  70. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/cluster_identifier_string.py +0 -0
  71. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/column_list.py +0 -0
  72. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/column_metadata.py +0 -0
  73. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/column_metadata_list.py +0 -0
  74. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/database_list.py +0 -0
  75. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/db_group_list.py +0 -0
  76. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/describe_statement_request.py +0 -0
  77. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/describe_statement_response.py +0 -0
  78. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/describe_table_request.py +0 -0
  79. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/describe_table_response.py +0 -0
  80. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/execute_statement_input.py +0 -0
  81. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/execute_statement_output.py +0 -0
  82. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/execution_mode.py +0 -0
  83. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/field.py +0 -0
  84. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/field_list.py +0 -0
  85. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/formatted_sql_records.py +0 -0
  86. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/get_statement_result_request.py +0 -0
  87. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/get_statement_result_response.py +0 -0
  88. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/get_statement_result_v2_request.py +0 -0
  89. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/get_statement_result_v2_response.py +0 -0
  90. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/integer.py +0 -0
  91. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/list_databases_request.py +0 -0
  92. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/list_databases_response.py +0 -0
  93. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/list_schemas_request.py +0 -0
  94. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/list_schemas_response.py +0 -0
  95. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/list_sessions_request.py +0 -0
  96. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/list_sessions_response.py +0 -0
  97. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/list_statements_limit.py +0 -0
  98. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/list_statements_request.py +0 -0
  99. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/list_statements_response.py +0 -0
  100. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/list_tables_request.py +0 -0
  101. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/list_tables_response.py +0 -0
  102. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/long.py +0 -0
  103. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/page_size.py +0 -0
  104. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/parameter_name.py +0 -0
  105. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/parameter_value.py +0 -0
  106. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/query_records.py +0 -0
  107. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/result_format_string.py +0 -0
  108. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/schema_list.py +0 -0
  109. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/secret_arn.py +0 -0
  110. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/session_alive_seconds.py +0 -0
  111. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/session_data.py +0 -0
  112. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/session_list.py +0 -0
  113. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/session_status_string.py +0 -0
  114. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/sql_list.py +0 -0
  115. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/sql_parameter.py +0 -0
  116. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/sql_parameters_list.py +0 -0
  117. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/sql_records.py +0 -0
  118. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/statement_data.py +0 -0
  119. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/statement_list.py +0 -0
  120. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/statement_name_string.py +0 -0
  121. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/statement_status_string.py +0 -0
  122. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/statement_string.py +0 -0
  123. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/statement_string_list.py +0 -0
  124. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/status_string.py +0 -0
  125. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/string.py +0 -0
  126. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/sub_statement_data.py +0 -0
  127. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/sub_statement_list.py +0 -0
  128. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/table_list.py +0 -0
  129. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/table_member.py +0 -0
  130. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/uuid.py +0 -0
  131. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/wait_time_seconds.py +0 -0
  132. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data/types/workgroup_name_string.py +0 -0
  133. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data.egg-info/SOURCES.txt +0 -0
  134. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data.egg-info/dependency_links.txt +0 -0
  135. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data.egg-info/requires.txt +0 -0
  136. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/src/capo_redshift_data.egg-info/top_level.txt +0 -0
  137. {capo_redshift_data-0.12.0 → capo_redshift_data-0.14.0}/tests/test_body.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: capo-redshift-data
3
- Version: 0.12.0
3
+ Version: 0.14.0
4
4
  Summary: Typed, async Python SDK for AWS Redshift Data.
5
5
  Project-URL: Homepage, https://capo-sdk.dev/
6
6
  Project-URL: Documentation, https://capo-sdk.dev/services/redshift-data/
@@ -94,6 +94,8 @@ The SDK retries failed operations automatically. Retry behaviour follows the Smi
94
94
 
95
95
  The number of attempts defaults to 3 and can be changed at the client level via `retry_max_attempts`, or per call via `config_overrides`.
96
96
 
97
+ `retry_mode="adaptive"` (or `AWS_RETRY_MODE=adaptive`, or `retry_mode = adaptive` in the AWS profile) also slows the whole client down once the service starts throttling it, then speeds back up as requests succeed. The default is `standard`.
98
+
97
99
  ```python
98
100
  from capo_redshift_data import AsyncRedshiftDataClient
99
101
 
@@ -62,6 +62,8 @@ The SDK retries failed operations automatically. Retry behaviour follows the Smi
62
62
 
63
63
  The number of attempts defaults to 3 and can be changed at the client level via `retry_max_attempts`, or per call via `config_overrides`.
64
64
 
65
+ `retry_mode="adaptive"` (or `AWS_RETRY_MODE=adaptive`, or `retry_mode = adaptive` in the AWS profile) also slows the whole client down once the service starts throttling it, then speeds back up as requests succeed. The default is `standard`.
66
+
65
67
  ```python
66
68
  from capo_redshift_data import AsyncRedshiftDataClient
67
69
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "capo-redshift-data"
3
- version = "0.12.0"
3
+ version = "0.14.0"
4
4
  description = "Typed, async Python SDK for AWS Redshift Data."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -471,12 +471,15 @@ def presign_sigv4(
471
471
  *,
472
472
  expires_in: int = 3600,
473
473
  now: _dt.datetime | None = None,
474
+ payload_hash: str = "UNSIGNED-PAYLOAD",
474
475
  ) -> Request:
475
476
  """Return a new ``Request`` whose URL carries SigV4 query-string auth.
476
477
 
477
478
  The signature travels in the URL (``X-Amz-*`` query params), so the result
478
479
  is usable standalone (browser, curl). Payload is signed as
479
- ``UNSIGNED-PAYLOAD``, so the body is not bound by the signature.
480
+ ``UNSIGNED-PAYLOAD``, so the body is not bound by the signature, unless
481
+ ``payload_hash`` says otherwise: an RDS or DSQL auth token signs the
482
+ SHA-256 of an empty body instead.
480
483
 
481
484
  ``expires_in`` is the validity window in seconds; range 1..604800 (7 days),
482
485
  bounded by the max lifetime of the derived signing key.
@@ -542,7 +545,7 @@ def presign_sigv4(
542
545
  f"{canonical_query}\n"
543
546
  f"{canonical_headers}\n"
544
547
  f"{signed_headers}\n"
545
- f"UNSIGNED-PAYLOAD"
548
+ f"{payload_hash}"
546
549
  )
547
550
 
548
551
  string_to_sign = (
@@ -31,6 +31,7 @@ class AwsSettings:
31
31
  use_fips: bool
32
32
  use_dual_stack: bool
33
33
  max_attempts: int
34
+ retry_mode: str
34
35
 
35
36
 
36
37
  def _env_bool(name: str) -> bool | None:
@@ -109,12 +110,22 @@ def load_aws_settings() -> AwsSettings:
109
110
  use_dual_stack = False
110
111
  max_attempts_raw = os.environ.get("AWS_MAX_ATTEMPTS") or profile.get("max_attempts")
111
112
  max_attempts = int(max_attempts_raw) if max_attempts_raw else 3
113
+ retry_mode = (
114
+ (os.environ.get("AWS_RETRY_MODE") or profile.get("retry_mode") or "standard")
115
+ .strip()
116
+ .lower()
117
+ )
118
+ if retry_mode not in ("legacy", "standard", "adaptive"):
119
+ raise ValueError(
120
+ f"invalid retry_mode {retry_mode!r}: expected 'legacy', 'standard' or 'adaptive'"
121
+ )
112
122
  return AwsSettings(
113
123
  region=region,
114
124
  endpoint=endpoint,
115
125
  use_fips=use_fips,
116
126
  use_dual_stack=use_dual_stack,
117
127
  max_attempts=max_attempts,
128
+ retry_mode=retry_mode,
118
129
  )
119
130
 
120
131
 
@@ -134,6 +145,8 @@ def aws_config() -> Interceptor[TInput, TOutput]:
134
145
  options.use_dual_stack = settings.use_dual_stack
135
146
  if options.retry_max_attempts is None:
136
147
  options.retry_max_attempts = settings.max_attempts
148
+ if options.retry_mode is None:
149
+ options.retry_mode = settings.retry_mode
137
150
  return next(request)
138
151
 
139
152
  return interceptor
@@ -155,6 +168,8 @@ def aaws_config() -> AsyncInterceptor[TInput, TOutput]:
155
168
  options.use_dual_stack = settings.use_dual_stack
156
169
  if options.retry_max_attempts is None:
157
170
  options.retry_max_attempts = settings.max_attempts
171
+ if options.retry_mode is None:
172
+ options.retry_mode = settings.retry_mode
158
173
  return await next(request)
159
174
 
160
175
  return interceptor
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import logging
4
+ import math
4
5
  import random
5
6
  import threading
6
7
  import time
@@ -88,15 +89,134 @@ class ThreadSafeRetryQuota(RetryQuota):
88
89
  super().release(last_retry_cost)
89
90
 
90
91
 
92
+ class RateLimiter:
93
+ """Send tokens shared by all operations of one client in adaptive retry mode: the rate drops on throttling and regrows on success."""
94
+
95
+ MIN_FILL_RATE: float = 0.5
96
+ MIN_CAPACITY: float = 1.0
97
+ BETA: float = 0.7
98
+ SCALE_CONSTANT: float = 0.4
99
+ SMOOTHING: float = 0.8
100
+ MAX_RATE_SCALE: float = 2.0
101
+
102
+ def __init__(self, clock: Callable[[], float] = time.monotonic) -> None:
103
+ self._clock = clock
104
+ now = clock()
105
+ self._enabled: bool = False
106
+ self._fill_rate: float = 1.0
107
+ self._max_capacity: float = 1.0
108
+ self._capacity: float = 0.0
109
+ self._last_refill: float = now
110
+ self._last_max_rate: float = 0.0
111
+ self._last_throttle: float = now
112
+ self._measured_rate: float = 0.0
113
+ self._rate_bucket: float = math.floor(now)
114
+ self._request_count: int = 0
115
+
116
+ def acquire(self) -> float:
117
+ """Take a send token: return 0, or the seconds to wait before asking again."""
118
+ if not self._enabled:
119
+ return 0.0
120
+ self._refill(self._clock())
121
+ if self._capacity >= 1:
122
+ self._capacity -= 1
123
+ return 0.0
124
+ return (1 - self._capacity) / self._fill_rate
125
+
126
+ def update(self, is_throttling: bool) -> None:
127
+ """Adjust the send rate after an attempt: cut it on throttling, regrow it otherwise."""
128
+ now = self._clock()
129
+ self._measure(now)
130
+ self._adjust(is_throttling, now)
131
+
132
+ def throttled_mid_stream(self) -> None:
133
+ """Cut the send rate for throttling reported inside an open event stream. No new request was sent, so the measured rate is left alone."""
134
+ self._adjust(True, self._clock())
135
+
136
+ def _adjust(self, is_throttling: bool, now: float) -> None:
137
+ if is_throttling:
138
+ rate = (
139
+ min(self._measured_rate, self._fill_rate)
140
+ if self._enabled
141
+ else self._measured_rate
142
+ )
143
+ self._last_max_rate = rate
144
+ self._last_throttle = now
145
+ new_rate = rate * self.BETA
146
+ self._enabled = True
147
+ else:
148
+ window = (self._last_max_rate * (1 - self.BETA) / self.SCALE_CONSTANT) ** (
149
+ 1 / 3
150
+ )
151
+ new_rate = (
152
+ self.SCALE_CONSTANT * (now - self._last_throttle - window) ** 3
153
+ + self._last_max_rate
154
+ )
155
+ self._set_rate(min(new_rate, self.MAX_RATE_SCALE * self._measured_rate), now)
156
+ if is_throttling:
157
+ logger.debug(
158
+ "throttled, send rate lowered to %.2f requests/s",
159
+ self._fill_rate,
160
+ extra={"send_rate": self._fill_rate},
161
+ )
162
+
163
+ def _refill(self, now: float) -> None:
164
+ self._capacity = min(
165
+ self._max_capacity,
166
+ self._capacity + (now - self._last_refill) * self._fill_rate,
167
+ )
168
+ self._last_refill = now
169
+
170
+ def _measure(self, now: float) -> None:
171
+ # Requests per second, counted in half-second buckets and smoothed.
172
+ bucket = math.floor(now * 2) / 2
173
+ self._request_count += 1
174
+ if bucket > self._rate_bucket:
175
+ current = self._request_count / (bucket - self._rate_bucket)
176
+ self._measured_rate = current * self.SMOOTHING + self._measured_rate * (
177
+ 1 - self.SMOOTHING
178
+ )
179
+ self._request_count = 0
180
+ self._rate_bucket = bucket
181
+
182
+ def _set_rate(self, rate: float, now: float) -> None:
183
+ self._refill(now)
184
+ self._fill_rate = max(rate, self.MIN_FILL_RATE)
185
+ self._max_capacity = max(rate, self.MIN_CAPACITY)
186
+ self._capacity = min(self._capacity, self._max_capacity)
187
+
188
+
189
+ class ThreadSafeRateLimiter(RateLimiter):
190
+ """A ``RateLimiter`` that sync clients can share across threads."""
191
+
192
+ def __init__(self, clock: Callable[[], float] = time.monotonic) -> None:
193
+ super().__init__(clock)
194
+ self._lock: threading.Lock = threading.Lock()
195
+
196
+ def acquire(self) -> float:
197
+ with self._lock:
198
+ return super().acquire()
199
+
200
+ def update(self, is_throttling: bool) -> None:
201
+ with self._lock:
202
+ super().update(is_throttling)
203
+
204
+ def throttled_mid_stream(self) -> None:
205
+ with self._lock:
206
+ super().throttled_mid_stream()
207
+
208
+
91
209
  @dataclass
92
210
  class OperationOptions:
93
211
  client: Client
94
212
  retry_quota: RetryQuota
213
+ rate_limiter: RateLimiter
95
214
  use_dual_stack: bool | None = None
96
215
  use_fips: bool | None = None
97
216
  region: str | None = None
98
217
  endpoint: str | None = None
99
218
  retry_max_attempts: int | None = None
219
+ retry_mode: str | None = None
100
220
  credentials_provider: IdentityProvider[Credentials] | None = None
101
221
  anonymous: bool | None = None
102
222
 
@@ -105,11 +225,13 @@ class OperationOptions:
105
225
  class AsyncOperationOptions:
106
226
  client: AsyncClient
107
227
  retry_quota: RetryQuota
228
+ rate_limiter: RateLimiter
108
229
  use_dual_stack: bool | None = None
109
230
  use_fips: bool | None = None
110
231
  region: str | None = None
111
232
  endpoint: str | None = None
112
233
  retry_max_attempts: int | None = None
234
+ retry_mode: str | None = None
113
235
  credentials_provider: IdentityProvider[Credentials] | None = None
114
236
  anonymous: bool | None = None
115
237
 
@@ -428,6 +550,91 @@ def aretry() -> AsyncInterceptor[TInput, TOutput]:
428
550
  return interceptor
429
551
 
430
552
 
553
+ def rate_limit() -> Interceptor[TInput, TOutput]:
554
+ def interceptor(
555
+ request: OperationRequest[TInput], next: NextFn[TInput, TOutput]
556
+ ) -> OperationResponse[TOutput]:
557
+ if request.options.retry_mode != "adaptive":
558
+ return next(request)
559
+ limiter = request.options.rate_limiter
560
+ while (wait := limiter.acquire()) > 0:
561
+ time.sleep(wait)
562
+ try:
563
+ response = next(request)
564
+ except Exception as exc:
565
+ limiter.update(isinstance(exc, ServiceError) and exc.is_throttling_error)
566
+ raise
567
+ limiter.update(False)
568
+ return response
569
+
570
+ return interceptor
571
+
572
+
573
+ def arate_limit() -> AsyncInterceptor[TInput, TOutput]:
574
+ async def interceptor(
575
+ request: AsyncOperationRequest[TInput], next: AsyncNextFn[TInput, TOutput]
576
+ ) -> AsyncOperationResponse[TOutput]:
577
+ if request.options.retry_mode != "adaptive":
578
+ return await next(request)
579
+ limiter = request.options.rate_limiter
580
+ while (wait := limiter.acquire()) > 0:
581
+ await anysleep(wait)
582
+ try:
583
+ response = await next(request)
584
+ except Exception as exc:
585
+ limiter.update(isinstance(exc, ServiceError) and exc.is_throttling_error)
586
+ raise
587
+ limiter.update(False)
588
+ return response
589
+
590
+ return interceptor
591
+
592
+
593
+ def _on_event_stream_error(
594
+ exc: ServiceError, options: OperationOptions | AsyncOperationOptions
595
+ ) -> None:
596
+ # An error event arrives after a 200 response, so raise_error never saw it:
597
+ # mark it by its code here. It is not retried, but adaptive mode slows down.
598
+ _apply_retry_rules(exc, exc.response)
599
+ if exc.is_throttling_error and options.retry_mode == "adaptive":
600
+ options.rate_limiter.throttled_mid_stream()
601
+
602
+
603
+ def watch_event_stream(output: Any, member: str, options: OperationOptions) -> None:
604
+ """Wrap the event stream ``output[member]`` so the errors it raises get their retry flags and reach the rate limiter."""
605
+ if member not in output:
606
+ return
607
+ events = output[member]
608
+
609
+ def watched() -> Iterator[Any]:
610
+ try:
611
+ yield from events
612
+ except ServiceError as exc:
613
+ _on_event_stream_error(exc, options)
614
+ raise
615
+
616
+ output[member] = watched()
617
+
618
+
619
+ def awatch_event_stream(
620
+ output: Any, member: str, options: AsyncOperationOptions
621
+ ) -> None:
622
+ """Wrap the event stream ``output[member]`` so the errors it raises get their retry flags and reach the rate limiter."""
623
+ if member not in output:
624
+ return
625
+ events = output[member]
626
+
627
+ async def watched() -> AsyncIterator[Any]:
628
+ try:
629
+ async for event in events:
630
+ yield event
631
+ except ServiceError as exc:
632
+ _on_event_stream_error(exc, options)
633
+ raise
634
+
635
+ output[member] = watched()
636
+
637
+
431
638
  def log_operation(operation_logging: OperationLogging) -> Interceptor[TInput, TOutput]:
432
639
  operation = operation_logging.operation
433
640
  redact_input = operation_logging.redact_input
@@ -3,7 +3,7 @@
3
3
  import uuid
4
4
  import warnings
5
5
  from collections.abc import AsyncIterator
6
- from typing import TYPE_CHECKING, Any, Iterable, Optional
6
+ from typing import TYPE_CHECKING, Any, Iterable, Literal, Optional
7
7
 
8
8
  from typing_extensions import Self, TypedDict
9
9
  from zapros import AsyncBaseHandler, AsyncClient
@@ -26,9 +26,11 @@ from capo_redshift_data._services._pipeline import (
26
26
  AsyncOperationRequest,
27
27
  AsyncOperationResponse,
28
28
  OperationLogging,
29
+ RateLimiter,
29
30
  RetryQuota,
30
31
  aexecute_pipeline,
31
32
  alog_operation,
33
+ arate_limit,
32
34
  aretry,
33
35
  )
34
36
 
@@ -86,6 +88,7 @@ if TYPE_CHECKING:
86
88
  class AsyncRedshiftDataClientConfig(TypedDict, total=False, closed=True):
87
89
  operation_interceptors: Iterable[AsyncInterceptor[Any, Any]]
88
90
  retry_max_attempts: int | None
91
+ retry_mode: Literal["standard", "adaptive"] | None
89
92
  region: str | None
90
93
  use_dual_stack: bool | None
91
94
  use_fips: bool | None
@@ -101,6 +104,7 @@ class AsyncRedshiftDataClient:
101
104
  http_handler: HTTP handler for sending requests. If not provided, creates a default handler.
102
105
  operation_interceptors: Interceptors that wrap every operation call. If not provided, defaults to an empty list.
103
106
  retry_max_attempts: Maximum number of times to retry a failed operation. Defaults to 3.
107
+ retry_mode: ``"standard"`` (the default) or ``"adaptive"``, which also slows the whole client down when the service throttles it.
104
108
  region: The value of the ``AWS::Region`` endpoint parameter.
105
109
  use_dual_stack: The value of the ``AWS::UseDualStack`` endpoint parameter.
106
110
  use_fips: The value of the ``AWS::UseFIPS`` endpoint parameter.
@@ -115,6 +119,7 @@ class AsyncRedshiftDataClient:
115
119
  http_handler: AsyncBaseHandler | None = None,
116
120
  operation_interceptors: Iterable[AsyncInterceptor[Any, Any]] | None = None,
117
121
  retry_max_attempts: int | None = None,
122
+ retry_mode: Literal["standard", "adaptive"] | None = None,
118
123
  region: str | None = None,
119
124
  use_dual_stack: bool | None = None,
120
125
  use_fips: bool | None = None,
@@ -131,6 +136,8 @@ class AsyncRedshiftDataClient:
131
136
  self._client = client.wrap_with_middleware(lambda next: AuthMiddleware(next))
132
137
  # One retry quota for all of this client's operations.
133
138
  self._retry_quota = RetryQuota()
139
+ # One send-rate limiter too, used when retry_mode is adaptive.
140
+ self._rate_limiter = RateLimiter()
134
141
  if credentials is not None and credentials_provider is not None:
135
142
  warnings.warn(
136
143
  "Both credentials and credentials_provider given; provider takes precedence"
@@ -148,6 +155,7 @@ class AsyncRedshiftDataClient:
148
155
  {
149
156
  "operation_interceptors": operation_interceptors or [],
150
157
  "retry_max_attempts": retry_max_attempts,
158
+ "retry_mode": retry_mode,
151
159
  "region": region,
152
160
  "use_dual_stack": use_dual_stack,
153
161
  "use_fips": use_fips,
@@ -172,12 +180,15 @@ class AsyncRedshiftDataClient:
172
180
  if operation_logging is not None:
173
181
  interceptors_.append(alog_operation(operation_logging))
174
182
  interceptors_.append(aretry())
183
+ interceptors_.append(arate_limit())
175
184
  options_: AsyncOperationOptions = AsyncOperationOptions(
176
185
  client=self._client,
177
186
  retry_quota=self._retry_quota,
187
+ rate_limiter=self._rate_limiter,
178
188
  retry_max_attempts=overrides.get(
179
189
  "retry_max_attempts", self._config.get("retry_max_attempts")
180
190
  ),
191
+ retry_mode=overrides.get("retry_mode", self._config.get("retry_mode")),
181
192
  region=overrides.get("region", self._config.get("region")),
182
193
  use_dual_stack=overrides.get(
183
194
  "use_dual_stack", self._config.get("use_dual_stack")
@@ -3,7 +3,7 @@
3
3
  import uuid
4
4
  import warnings
5
5
  from collections.abc import Iterator
6
- from typing import TYPE_CHECKING, Any, Iterable, Optional
6
+ from typing import TYPE_CHECKING, Any, Iterable, Literal, Optional
7
7
 
8
8
  from typing_extensions import Self, TypedDict
9
9
  from zapros import BaseHandler, Client
@@ -26,9 +26,11 @@ from capo_redshift_data._services._pipeline import (
26
26
  OperationOptions,
27
27
  OperationRequest,
28
28
  OperationResponse,
29
+ ThreadSafeRateLimiter,
29
30
  ThreadSafeRetryQuota,
30
31
  execute_pipeline,
31
32
  log_operation,
33
+ rate_limit,
32
34
  retry,
33
35
  )
34
36
 
@@ -86,6 +88,7 @@ if TYPE_CHECKING:
86
88
  class RedshiftDataClientConfig(TypedDict, total=False, closed=True):
87
89
  operation_interceptors: Iterable[Interceptor[Any, Any]]
88
90
  retry_max_attempts: int | None
91
+ retry_mode: Literal["standard", "adaptive"] | None
89
92
  region: str | None
90
93
  use_dual_stack: bool | None
91
94
  use_fips: bool | None
@@ -101,6 +104,7 @@ class RedshiftDataClient:
101
104
  http_handler: HTTP handler for sending requests. If not provided, creates a default handler.
102
105
  operation_interceptors: Interceptors that wrap every operation call. If not provided, defaults to an empty list.
103
106
  retry_max_attempts: Maximum number of times to retry a failed operation. Defaults to 3.
107
+ retry_mode: ``"standard"`` (the default) or ``"adaptive"``, which also slows the whole client down when the service throttles it.
104
108
  region: The value of the ``AWS::Region`` endpoint parameter.
105
109
  use_dual_stack: The value of the ``AWS::UseDualStack`` endpoint parameter.
106
110
  use_fips: The value of the ``AWS::UseFIPS`` endpoint parameter.
@@ -115,6 +119,7 @@ class RedshiftDataClient:
115
119
  http_handler: BaseHandler | None = None,
116
120
  operation_interceptors: Iterable[Interceptor[Any, Any]] | None = None,
117
121
  retry_max_attempts: int | None = None,
122
+ retry_mode: Literal["standard", "adaptive"] | None = None,
118
123
  region: str | None = None,
119
124
  use_dual_stack: bool | None = None,
120
125
  use_fips: bool | None = None,
@@ -131,6 +136,8 @@ class RedshiftDataClient:
131
136
  self._client = client.wrap_with_middleware(lambda next: AuthMiddleware(next))
132
137
  # One retry quota for all of this client's operations.
133
138
  self._retry_quota = ThreadSafeRetryQuota()
139
+ # One send-rate limiter too, used when retry_mode is adaptive.
140
+ self._rate_limiter = ThreadSafeRateLimiter()
134
141
  if credentials is not None and credentials_provider is not None:
135
142
  warnings.warn(
136
143
  "Both credentials and credentials_provider given; provider takes precedence"
@@ -148,6 +155,7 @@ class RedshiftDataClient:
148
155
  {
149
156
  "operation_interceptors": operation_interceptors or [],
150
157
  "retry_max_attempts": retry_max_attempts,
158
+ "retry_mode": retry_mode,
151
159
  "region": region,
152
160
  "use_dual_stack": use_dual_stack,
153
161
  "use_fips": use_fips,
@@ -172,12 +180,15 @@ class RedshiftDataClient:
172
180
  if operation_logging is not None:
173
181
  interceptors_.append(log_operation(operation_logging))
174
182
  interceptors_.append(retry())
183
+ interceptors_.append(rate_limit())
175
184
  options_: OperationOptions = OperationOptions(
176
185
  client=self._client,
177
186
  retry_quota=self._retry_quota,
187
+ rate_limiter=self._rate_limiter,
178
188
  retry_max_attempts=overrides.get(
179
189
  "retry_max_attempts", self._config.get("retry_max_attempts")
180
190
  ),
191
+ retry_mode=overrides.get("retry_mode", self._config.get("retry_mode")),
181
192
  region=overrides.get("region", self._config.get("region")),
182
193
  use_dual_stack=overrides.get(
183
194
  "use_dual_stack", self._config.get("use_dual_stack")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: capo-redshift-data
3
- Version: 0.12.0
3
+ Version: 0.14.0
4
4
  Summary: Typed, async Python SDK for AWS Redshift Data.
5
5
  Project-URL: Homepage, https://capo-sdk.dev/
6
6
  Project-URL: Documentation, https://capo-sdk.dev/services/redshift-data/
@@ -94,6 +94,8 @@ The SDK retries failed operations automatically. Retry behaviour follows the Smi
94
94
 
95
95
  The number of attempts defaults to 3 and can be changed at the client level via `retry_max_attempts`, or per call via `config_overrides`.
96
96
 
97
+ `retry_mode="adaptive"` (or `AWS_RETRY_MODE=adaptive`, or `retry_mode = adaptive` in the AWS profile) also slows the whole client down once the service starts throttling it, then speeds back up as requests succeed. The default is `standard`.
98
+
97
99
  ```python
98
100
  from capo_redshift_data import AsyncRedshiftDataClient
99
101
 
@@ -36,6 +36,7 @@ from capo_redshift_data._auth._sigv4 import (
36
36
  _derive_signing_key,
37
37
  _trim_header_value,
38
38
  _uri_encode,
39
+ presign_sigv4,
39
40
  sign_sigv4,
40
41
  )
41
42
  from capo_redshift_data._protocol.eventstream import Message, MessageDecoder, encode_headers
@@ -356,6 +357,38 @@ def test_s3_get_object_example():
356
357
  # ---------------------------------------------------------------------------
357
358
 
358
359
 
360
+ def test_presign_signs_the_given_payload_hash():
361
+ """An RDS IAM auth token signs the SHA-256 of an empty body, not
362
+ UNSIGNED-PAYLOAD. The vector is botocore's ``generate_db_auth_token`` for
363
+ the same host, user, region, credentials and clock."""
364
+ req = Request(
365
+ URL(
366
+ "https://db.abc.us-east-1.rds.amazonaws.com:5432/"
367
+ "?Action=connect&DBUser=app+user%40x"
368
+ ),
369
+ "GET",
370
+ )
371
+ ctx: SigV4AuthContext = {
372
+ **_TEST_SUITE_CTX,
373
+ "signing_region": "eu-west-1",
374
+ "signing_name": "rds-db",
375
+ }
376
+ presigned = presign_sigv4(
377
+ req,
378
+ ctx,
379
+ expires_in=900,
380
+ now=dt.datetime(2026, 11, 21, 12, 0, tzinfo=dt.timezone.utc),
381
+ payload_hash=hashlib.sha256(b"").hexdigest(),
382
+ )
383
+ assert str(presigned.url) == (
384
+ "https://db.abc.us-east-1.rds.amazonaws.com:5432/?Action=connect"
385
+ "&DBUser=app%20user%40x&X-Amz-Algorithm=AWS4-HMAC-SHA256"
386
+ "&X-Amz-Credential=AKIDEXAMPLE%2F20261121%2Feu-west-1%2Frds-db%2Faws4_request"
387
+ "&X-Amz-Date=20261121T120000Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host"
388
+ "&X-Amz-Signature=c949b1e47c86c7b6d7d8d2390316cd9c4c2f801a203e802b1bc961ebabefd08e"
389
+ )
390
+
391
+
359
392
  def test_session_token_added_and_signed():
360
393
  ctx: SigV4AuthContext = {**_TEST_SUITE_CTX, "session_token": "TOKEN123"}
361
394
  req = _make_request(