cc-platform-sdk 1.0.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 (118) hide show
  1. cc_platform_sdk-1.0.0/.gitignore +7 -0
  2. cc_platform_sdk-1.0.0/CHANGELOG.md +44 -0
  3. cc_platform_sdk-1.0.0/LICENSE +191 -0
  4. cc_platform_sdk-1.0.0/PKG-INFO +40 -0
  5. cc_platform_sdk-1.0.0/README.md +133 -0
  6. cc_platform_sdk-1.0.0/pyproject.toml +51 -0
  7. cc_platform_sdk-1.0.0/src/cc_platform_sdk/__init__.py +11 -0
  8. cc_platform_sdk-1.0.0/src/cc_platform_sdk/auth/__init__.py +106 -0
  9. cc_platform_sdk-1.0.0/src/cc_platform_sdk/auth/acting_user.py +288 -0
  10. cc_platform_sdk-1.0.0/src/cc_platform_sdk/auth/config.py +150 -0
  11. cc_platform_sdk-1.0.0/src/cc_platform_sdk/auth/credential_provider.py +177 -0
  12. cc_platform_sdk-1.0.0/src/cc_platform_sdk/auth/exceptions.py +113 -0
  13. cc_platform_sdk-1.0.0/src/cc_platform_sdk/auth/jwks_client.py +287 -0
  14. cc_platform_sdk-1.0.0/src/cc_platform_sdk/auth/middleware.py +210 -0
  15. cc_platform_sdk-1.0.0/src/cc_platform_sdk/auth/models.py +190 -0
  16. cc_platform_sdk-1.0.0/src/cc_platform_sdk/auth/security_identity.py +167 -0
  17. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/__init__.py +13 -0
  18. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/config/__init__.py +59 -0
  19. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/config/settings.py +110 -0
  20. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/config/standard_config.py +489 -0
  21. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/context/__init__.py +83 -0
  22. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/context/context.py +552 -0
  23. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/context/middleware.py +135 -0
  24. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/errors/__init__.py +118 -0
  25. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/errors/catalog.py +541 -0
  26. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/errors/codes.py +267 -0
  27. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/errors/exceptions.py +349 -0
  28. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/errors/protocol_mappings.py +288 -0
  29. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/feature_flags/__init__.py +29 -0
  30. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/feature_flags/provider.py +108 -0
  31. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/feature_flags/types.py +137 -0
  32. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/protocol/__init__.py +94 -0
  33. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/protocol/envelope.py +317 -0
  34. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/protocol/headers.py +215 -0
  35. cc_platform_sdk-1.0.0/src/cc_platform_sdk/core/protocol/service_tier.py +119 -0
  36. cc_platform_sdk-1.0.0/src/cc_platform_sdk/events/__init__.py +16 -0
  37. cc_platform_sdk-1.0.0/src/cc_platform_sdk/events/envelope.py +104 -0
  38. cc_platform_sdk-1.0.0/src/cc_platform_sdk/events/validation.py +21 -0
  39. cc_platform_sdk-1.0.0/src/cc_platform_sdk/infra/__init__.py +1 -0
  40. cc_platform_sdk-1.0.0/src/cc_platform_sdk/infra/cache/__init__.py +23 -0
  41. cc_platform_sdk-1.0.0/src/cc_platform_sdk/infra/cache/client.py +318 -0
  42. cc_platform_sdk-1.0.0/src/cc_platform_sdk/infra/ratelimit/__init__.py +22 -0
  43. cc_platform_sdk-1.0.0/src/cc_platform_sdk/infra/ratelimit/config.py +199 -0
  44. cc_platform_sdk-1.0.0/src/cc_platform_sdk/infra/ratelimit/limiter.py +276 -0
  45. cc_platform_sdk-1.0.0/src/cc_platform_sdk/lifecycle/__init__.py +53 -0
  46. cc_platform_sdk-1.0.0/src/cc_platform_sdk/lifecycle/health.py +83 -0
  47. cc_platform_sdk-1.0.0/src/cc_platform_sdk/lifecycle/lifecycle.py +338 -0
  48. cc_platform_sdk-1.0.0/src/cc_platform_sdk/lifecycle/types.py +147 -0
  49. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/__init__.py +96 -0
  50. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/correlation.py +177 -0
  51. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/diagnostics.py +116 -0
  52. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/envelope.py +140 -0
  53. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/instrumentation.py +326 -0
  54. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/interfaces.py +196 -0
  55. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/logging/__init__.py +7 -0
  56. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/logging/logger.py +119 -0
  57. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/metrics/__init__.py +8 -0
  58. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/metrics/helpers.py +67 -0
  59. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/metrics/registry.py +260 -0
  60. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/noop.py +128 -0
  61. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/tracing/__init__.py +27 -0
  62. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/tracing/config.py +55 -0
  63. cc_platform_sdk-1.0.0/src/cc_platform_sdk/observability/tracing/tracer.py +338 -0
  64. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/__init__.py +1 -0
  65. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/grpc/__init__.py +28 -0
  66. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/grpc/interceptors.py +561 -0
  67. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/http/__init__.py +41 -0
  68. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/http/client.py +515 -0
  69. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/http/retry.py +294 -0
  70. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/kafka/__init__.py +50 -0
  71. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/kafka/consumer.py +479 -0
  72. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/kafka/errors.py +127 -0
  73. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/kafka/producer.py +383 -0
  74. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/serviceclient/__init__.py +87 -0
  75. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/serviceclient/client.py +209 -0
  76. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/serviceclient/discovery.py +89 -0
  77. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/serviceclient/grpc_adapter.py +138 -0
  78. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/serviceclient/http_adapter.py +143 -0
  79. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/serviceclient/kafka_adapter.py +91 -0
  80. cc_platform_sdk-1.0.0/src/cc_platform_sdk/transport/serviceclient/types.py +211 -0
  81. cc_platform_sdk-1.0.0/src/cc_platform_sdk/utils/__init__.py +37 -0
  82. cc_platform_sdk-1.0.0/src/cc_platform_sdk/utils/ids.py +53 -0
  83. cc_platform_sdk-1.0.0/src/cc_platform_sdk/utils/serialization.py +99 -0
  84. cc_platform_sdk-1.0.0/src/cc_platform_sdk/utils/time.py +76 -0
  85. cc_platform_sdk-1.0.0/tests/__init__.py +0 -0
  86. cc_platform_sdk-1.0.0/tests/conformance/__init__.py +0 -0
  87. cc_platform_sdk-1.0.0/tests/conformance/loader.py +97 -0
  88. cc_platform_sdk-1.0.0/tests/conformance/test_all_specs.py +53 -0
  89. cc_platform_sdk-1.0.0/tests/conformance/test_auth.py +1371 -0
  90. cc_platform_sdk-1.0.0/tests/conformance/test_errors.py +367 -0
  91. cc_platform_sdk-1.0.0/tests/conformance/test_events.py +139 -0
  92. cc_platform_sdk-1.0.0/tests/conformance/test_observability.py +930 -0
  93. cc_platform_sdk-1.0.0/tests/conformance/test_protocol.py +343 -0
  94. cc_platform_sdk-1.0.0/tests/unit/__init__.py +0 -0
  95. cc_platform_sdk-1.0.0/tests/unit/auth/__init__.py +0 -0
  96. cc_platform_sdk-1.0.0/tests/unit/auth/test_credential_provider.py +192 -0
  97. cc_platform_sdk-1.0.0/tests/unit/auth/test_middleware.py +285 -0
  98. cc_platform_sdk-1.0.0/tests/unit/auth/test_security_identity.py +168 -0
  99. cc_platform_sdk-1.0.0/tests/unit/config/__init__.py +0 -0
  100. cc_platform_sdk-1.0.0/tests/unit/config/test_standard_config.py +433 -0
  101. cc_platform_sdk-1.0.0/tests/unit/context/__init__.py +0 -0
  102. cc_platform_sdk-1.0.0/tests/unit/context/test_propagation.py +308 -0
  103. cc_platform_sdk-1.0.0/tests/unit/context/test_security_identity_context.py +219 -0
  104. cc_platform_sdk-1.0.0/tests/unit/feature_flags/__init__.py +0 -0
  105. cc_platform_sdk-1.0.0/tests/unit/feature_flags/test_provider.py +211 -0
  106. cc_platform_sdk-1.0.0/tests/unit/lifecycle/__init__.py +0 -0
  107. cc_platform_sdk-1.0.0/tests/unit/lifecycle/test_lifecycle.py +571 -0
  108. cc_platform_sdk-1.0.0/tests/unit/observability/__init__.py +0 -0
  109. cc_platform_sdk-1.0.0/tests/unit/observability/test_correlation.py +226 -0
  110. cc_platform_sdk-1.0.0/tests/unit/observability/test_hooks.py +417 -0
  111. cc_platform_sdk-1.0.0/tests/unit/observability/test_instrumentation.py +385 -0
  112. cc_platform_sdk-1.0.0/tests/unit/observability/test_interfaces.py +418 -0
  113. cc_platform_sdk-1.0.0/tests/unit/observability/test_parity.py +442 -0
  114. cc_platform_sdk-1.0.0/tests/unit/transport/__init__.py +0 -0
  115. cc_platform_sdk-1.0.0/tests/unit/transport/test_abstraction.py +285 -0
  116. cc_platform_sdk-1.0.0/tests/unit/transport/test_retry_integration.py +490 -0
  117. cc_platform_sdk-1.0.0/tests/unit/transport/test_service_client.py +355 -0
  118. cc_platform_sdk-1.0.0/uv.lock +1040 -0
@@ -0,0 +1,7 @@
1
+ node_modules/
2
+ dist/
3
+ .DS_Store
4
+ *.local
5
+ .env
6
+ .env.*
7
+ !.env.example
@@ -0,0 +1,44 @@
1
+ # Changelog
2
+
3
+ All notable changes to `cc-platform-sdk` will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2026-03-10
9
+
10
+ ### Added
11
+
12
+ - Core error taxonomy (50 error codes, 10 categories, HTTP/gRPC mappings)
13
+ - Protocol envelopes (request/response) with service tier retry configs
14
+ - BaseServiceSettings (Pydantic-based) with environment detection
15
+ - StandardConfig model (timeouts, retry policy, transport, auth, observability)
16
+ - RequestContext propagation (correlation ID, trace ID, span ID, tenant, security identity)
17
+ - Context scope manager and ASGI middleware for automatic header extraction
18
+ - Structured logging (structlog-based, JSON format)
19
+ - Prometheus metrics (MetricRegistry with auto-injected service/env labels)
20
+ - OpenTelemetry tracing integration
21
+ - HTTP client (httpx-based) with circuit breaker, retry, transport error classification
22
+ - Retry classification (retryable, non_retryable, rate_limited, transient, permanent)
23
+ - Lifecycle-aware retry with per-attempt gate checks
24
+ - gRPC client/server interceptors with context-propagating interceptor chains
25
+ - Kafka producer/consumer (aiokafka-based) with DLQ support and event envelope serialization
26
+ - Transport-agnostic service client with service discovery and token provider
27
+ - HTTP, gRPC, and Kafka transport adapters with 7 canonical error categories
28
+ - Async Redis cache helpers with connection pooling and health checks
29
+ - Rate limiting with sliding window algorithm and environment-based multipliers
30
+ - JWT/JWKS authentication with rotation handling and configurable leeway
31
+ - SecurityIdentity contract (frozen dataclass, immutable)
32
+ - CredentialProvider protocol (runtime_checkable, outbound credential injection)
33
+ - Acting-user HMAC signing and verification
34
+ - Auth middleware hooks (framework-agnostic)
35
+ - Event envelope creation and validation
36
+ - Hook-based lifecycle management (asyncio, init/ready/health/shutdown) with observer
37
+ - Lifecycle observer pattern with 7 event types
38
+ - Feature flag provider protocol (fail-closed semantics, InMemoryProvider)
39
+ - Vendor-neutral observability interfaces (Logger, MetricsRecorder, Tracer, Span) with noop defaults
40
+ - Observability envelope with context extraction
41
+ - Diagnostics collector for transport/pool/retry/dependency health
42
+ - Instrumentation hooks (vendor-neutral metrics/tracing/logging)
43
+ - Correlation ID propagation (req_<12hex> format)
44
+ - Utility functions for ID generation, UTC time, and JSON serialization
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2026 Conscious Clouds
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
@@ -0,0 +1,40 @@
1
+ Metadata-Version: 2.4
2
+ Name: cc-platform-sdk
3
+ Version: 1.0.0
4
+ Summary: Conscious Clouds Platform SDK for Python
5
+ License: Apache-2.0
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.11
8
+ Requires-Dist: httpx<1.0.0,>=0.27.0
9
+ Requires-Dist: prometheus-client<1.0.0,>=0.20.0
10
+ Requires-Dist: pydantic-settings<3.0.0,>=2.0.0
11
+ Requires-Dist: pydantic<3.0.0,>=2.0.0
12
+ Requires-Dist: pyjwt[crypto]<3.0.0,>=2.8.0
13
+ Requires-Dist: redis[hiredis]<6.0.0,>=5.0.0
14
+ Requires-Dist: structlog<25.0.0,>=23.2.0
15
+ Provides-Extra: all
16
+ Requires-Dist: aiokafka<1.0.0,>=0.10.0; extra == 'all'
17
+ Requires-Dist: grpcio-health-checking<2.0.0,>=1.60.0; extra == 'all'
18
+ Requires-Dist: grpcio-reflection<2.0.0,>=1.60.0; extra == 'all'
19
+ Requires-Dist: grpcio<2.0.0,>=1.60.0; extra == 'all'
20
+ Requires-Dist: opentelemetry-api<2.0.0,>=1.27.0; extra == 'all'
21
+ Requires-Dist: opentelemetry-exporter-otlp<2.0.0,>=1.27.0; extra == 'all'
22
+ Requires-Dist: opentelemetry-sdk<2.0.0,>=1.27.0; extra == 'all'
23
+ Requires-Dist: pytest-asyncio<1.0.0,>=0.23.0; extra == 'all'
24
+ Requires-Dist: pytest<9.0.0,>=8.0.0; extra == 'all'
25
+ Requires-Dist: starlette<1.0.0,>=0.27.0; extra == 'all'
26
+ Provides-Extra: grpc
27
+ Requires-Dist: grpcio-health-checking<2.0.0,>=1.60.0; extra == 'grpc'
28
+ Requires-Dist: grpcio-reflection<2.0.0,>=1.60.0; extra == 'grpc'
29
+ Requires-Dist: grpcio<2.0.0,>=1.60.0; extra == 'grpc'
30
+ Provides-Extra: kafka
31
+ Requires-Dist: aiokafka<1.0.0,>=0.10.0; extra == 'kafka'
32
+ Provides-Extra: test
33
+ Requires-Dist: pytest-asyncio<1.0.0,>=0.23.0; extra == 'test'
34
+ Requires-Dist: pytest<9.0.0,>=8.0.0; extra == 'test'
35
+ Provides-Extra: tracing
36
+ Requires-Dist: opentelemetry-api<2.0.0,>=1.27.0; extra == 'tracing'
37
+ Requires-Dist: opentelemetry-exporter-otlp<2.0.0,>=1.27.0; extra == 'tracing'
38
+ Requires-Dist: opentelemetry-sdk<2.0.0,>=1.27.0; extra == 'tracing'
39
+ Provides-Extra: web
40
+ Requires-Dist: starlette<1.0.0,>=0.27.0; extra == 'web'
@@ -0,0 +1,133 @@
1
+ # cc-platform-sdk -- Conscious Clouds Platform SDK for Python
2
+
3
+ A framework-agnostic SDK providing standardized patterns for microservice
4
+ development: error handling, protocol envelopes, observability, authentication,
5
+ transport, and infrastructure utilities.
6
+
7
+ This SDK contains zero product-specific references. Products extend it with
8
+ their own defaults, event catalogs, and framework plugins.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ pip install cc-platform-sdk
14
+ ```
15
+
16
+ With optional extras:
17
+
18
+ ```bash
19
+ pip install cc-platform-sdk[grpc] # gRPC transport support
20
+ pip install cc-platform-sdk[kafka] # Kafka transport support
21
+ pip install cc-platform-sdk[tracing] # OpenTelemetry tracing
22
+ pip install cc-platform-sdk[web] # ASGI middleware (Starlette)
23
+ pip install cc-platform-sdk[all] # All optional dependencies
24
+ ```
25
+
26
+ ## Requirements
27
+
28
+ - Python >= 3.11
29
+
30
+ ## Quick Start
31
+
32
+ ```python
33
+ from cc_platform_sdk.core.errors import ErrorCode, PlatformException, get_http_status
34
+ from cc_platform_sdk.core.config import BaseServiceSettings
35
+ from cc_platform_sdk.core.context import context_scope, get_correlation_id
36
+ from cc_platform_sdk.observability.logging import get_logger
37
+
38
+ # Configure service settings
39
+ class MySettings(BaseServiceSettings):
40
+ database_url: str = "postgresql://localhost/mydb"
41
+
42
+ settings = MySettings(service_name="order-service", environment="dev")
43
+
44
+ # Use structured logging
45
+ logger = get_logger(__name__)
46
+ logger.info("service_starting", service=settings.service_name)
47
+
48
+ # Error handling with platform error codes
49
+ http_status = get_http_status(ErrorCode.RESOURCE_NOT_FOUND) # 404
50
+
51
+ # Context propagation
52
+ with context_scope(correlation_id="req_abc123def456", tenant_id="t_acme"):
53
+ cid = get_correlation_id() # "req_abc123def456"
54
+ logger.info("request_received", correlation_id=cid)
55
+ ```
56
+
57
+ ## Modules
58
+
59
+ | Module | Description |
60
+ |--------|-------------|
61
+ | `cc_platform_sdk.auth` | JWT/JWKS validation, SecurityIdentity (frozen dataclass, immutable), CredentialProvider protocol (runtime_checkable, outbound credential injection), acting-user HMAC signing and verification, auth middleware hooks (framework-agnostic) |
62
+ | `cc_platform_sdk.core.config` | BaseServiceSettings (Pydantic-based) with environment detection, StandardConfig model with timeouts, retry policy, transport, auth, and observability sections |
63
+ | `cc_platform_sdk.core.context` | RequestContext propagation via contextvars (correlation ID, trace ID, span ID, tenant, user, security identity, session, environment), context scope manager, ASGI middleware |
64
+ | `cc_platform_sdk.core.errors` | Error codes (50 codes, 10 categories), error catalog with HTTP/gRPC status mappings, typed exception hierarchy (PlatformException and 9 category subclasses), retryability classification |
65
+ | `cc_platform_sdk.core.feature_flags` | FeatureFlagProvider protocol, InMemoryFeatureFlagProvider, fail-closed semantics (unknown flags return false/default), EvaluationContext for targeting |
66
+ | `cc_platform_sdk.core.protocol` | Request/response envelopes, service tier definitions with retry configs, standard header propagation (correlation ID, trace ID, tenant ID, etc.) |
67
+ | `cc_platform_sdk.events` | Event envelope creation and validation, event type format enforcement |
68
+ | `cc_platform_sdk.infra.cache` | Async Redis cache helpers with connection pooling, JSON get/set, key deletion, health checks |
69
+ | `cc_platform_sdk.infra.ratelimit` | Rate limiting with sliding window algorithm, configurable rules, environment-based multipliers |
70
+ | `cc_platform_sdk.lifecycle` | Hook-based lifecycle management (asyncio): ordered startup, reverse-order shutdown, health aggregation, startup rollback, observer pattern with 7 event types |
71
+ | `cc_platform_sdk.observability` | Vendor-neutral observability interfaces (Logger, MetricsRecorder, Tracer, Span) with noop defaults, observability envelope, correlation propagation, diagnostics collector, instrumentation hooks |
72
+ | `cc_platform_sdk.observability.logging` | Structured logging via structlog (JSON format), correlation ID integration |
73
+ | `cc_platform_sdk.observability.metrics` | Prometheus metrics via MetricRegistry with auto-injected service/env labels, bounded cardinality helpers |
74
+ | `cc_platform_sdk.observability.tracing` | OpenTelemetry tracing with OTLP exporter, span management, function decorator |
75
+ | `cc_platform_sdk.transport.grpc` | gRPC server/client interceptors for context propagation, logging, metrics, and error handling; interceptor chain builders |
76
+ | `cc_platform_sdk.transport.http` | HTTP client (httpx-based) with circuit breaker, retry with lifecycle gate, retry classification (5 categories: retryable, non_retryable, rate_limited, transient, permanent) |
77
+ | `cc_platform_sdk.transport.kafka` | Kafka producer/consumer (aiokafka-based) with DLQ support, event envelope serialization, compression, configurable acks |
78
+ | `cc_platform_sdk.transport.serviceclient` | Transport-agnostic service client with service discovery (env-based, static), token provider protocol, HTTP/gRPC/Kafka transport adapters, 7 canonical error categories |
79
+ | `cc_platform_sdk.utils` | ID generation (UUID, correlation ID), UTC time helpers (ISO 8601), JSON serialization utilities |
80
+
81
+ ## Optional Dependencies
82
+
83
+ The following extras install additional dependencies for specific transport and
84
+ observability features:
85
+
86
+ ### `grpc`
87
+
88
+ gRPC transport support. Required for `cc_platform_sdk.transport.grpc`.
89
+
90
+ - `grpcio >= 1.60.0`
91
+ - `grpcio-health-checking >= 1.60.0`
92
+ - `grpcio-reflection >= 1.60.0`
93
+
94
+ ### `kafka`
95
+
96
+ Kafka transport support. Required for `cc_platform_sdk.transport.kafka`.
97
+
98
+ - `aiokafka >= 0.10.0`
99
+
100
+ ### `tracing`
101
+
102
+ OpenTelemetry tracing. Required for `cc_platform_sdk.observability.tracing`.
103
+
104
+ - `opentelemetry-api >= 1.27.0`
105
+ - `opentelemetry-sdk >= 1.27.0`
106
+ - `opentelemetry-exporter-otlp >= 1.27.0`
107
+
108
+ ### `web`
109
+
110
+ ASGI middleware support for `cc_platform_sdk.core.context.ContextMiddleware`.
111
+
112
+ - `starlette >= 0.27.0`
113
+
114
+ ### `test`
115
+
116
+ Test runner dependencies for running the SDK's own test suite.
117
+
118
+ - `pytest >= 8.0.0`
119
+ - `pytest-asyncio >= 0.23.0`
120
+
121
+ ### `all`
122
+
123
+ Installs all optional dependencies: `grpc`, `kafka`, `tracing`, `web`, `test`.
124
+
125
+ ## Testing
126
+
127
+ For test harnesses and mock utilities used to test services built on this SDK,
128
+ see the companion package
129
+ [`cc-platform-sdk-testing`](https://github.com/consciousclouds/cc-platform-sdk-testing).
130
+
131
+ ## License
132
+
133
+ Apache 2.0 -- see [LICENSE](./LICENSE).
@@ -0,0 +1,51 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "cc-platform-sdk"
7
+ version = "1.0.0"
8
+ description = "Conscious Clouds Platform SDK for Python"
9
+ license = {text = "Apache-2.0"}
10
+ requires-python = ">=3.11"
11
+ dependencies = [
12
+ "pydantic>=2.0.0,<3.0.0",
13
+ "pydantic-settings>=2.0.0,<3.0.0",
14
+ "structlog>=23.2.0,<25.0.0",
15
+ "prometheus-client>=0.20.0,<1.0.0",
16
+ "httpx>=0.27.0,<1.0.0",
17
+ "redis[hiredis]>=5.0.0,<6.0.0",
18
+ "PyJWT[crypto]>=2.8.0,<3.0.0",
19
+ ]
20
+
21
+ [project.optional-dependencies]
22
+ grpc = [
23
+ "grpcio>=1.60.0,<2.0.0",
24
+ "grpcio-health-checking>=1.60.0,<2.0.0",
25
+ "grpcio-reflection>=1.60.0,<2.0.0",
26
+ ]
27
+ kafka = [
28
+ "aiokafka>=0.10.0,<1.0.0",
29
+ ]
30
+ tracing = [
31
+ "opentelemetry-api>=1.27.0,<2.0.0",
32
+ "opentelemetry-sdk>=1.27.0,<2.0.0",
33
+ "opentelemetry-exporter-otlp>=1.27.0,<2.0.0",
34
+ ]
35
+ web = [
36
+ "starlette>=0.27.0,<1.0.0",
37
+ ]
38
+ test = [
39
+ "pytest>=8.0.0,<9.0.0",
40
+ "pytest-asyncio>=0.23.0,<1.0.0",
41
+ ]
42
+ all = [
43
+ "cc-platform-sdk[grpc,kafka,tracing,web,test]",
44
+ ]
45
+
46
+ [tool.hatch.build.targets.wheel]
47
+ packages = ["src/cc_platform_sdk"]
48
+
49
+ [tool.pytest.ini_options]
50
+ testpaths = ["tests"]
51
+ asyncio_mode = "auto"
@@ -0,0 +1,11 @@
1
+ """Conscious Clouds Platform SDK for Python.
2
+
3
+ A framework-agnostic SDK providing standardized patterns for microservice
4
+ development: error handling, protocol envelopes, observability, auth,
5
+ transport, and infrastructure utilities.
6
+
7
+ This SDK contains zero product-specific references. Products (ENO, Omni, etc.)
8
+ extend it with their own defaults, event catalogs, and framework plugins.
9
+ """
10
+
11
+ __version__ = "1.0.0"
@@ -0,0 +1,106 @@
1
+ """Authentication and authorization primitives.
2
+
3
+ Provides JWT validation via JWKS, token payload models, acting-user
4
+ HMAC verification, credential providers for outbound authentication,
5
+ canonical security identity, and a typed exception hierarchy. All
6
+ symbols are re-exported from submodules for convenient single-import
7
+ usage::
8
+
9
+ from cc_platform_sdk.auth import (
10
+ AuthConfig,
11
+ JWKSClient,
12
+ TokenPayload,
13
+ UserClaims,
14
+ SecurityIdentity,
15
+ CredentialProvider,
16
+ InvalidTokenError,
17
+ )
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ from cc_platform_sdk.auth.acting_user import (
23
+ ActingUserContext,
24
+ HeaderNames,
25
+ extract_acting_user_headers,
26
+ sign_acting_user_headers,
27
+ verify_acting_user_signature,
28
+ )
29
+ from cc_platform_sdk.auth.config import AuthConfig, validate_config
30
+ from cc_platform_sdk.auth.credential_provider import (
31
+ BearerTokenProvider,
32
+ CredentialProvider,
33
+ CredentialResult,
34
+ MtlsConfig,
35
+ NoopCredentialProvider,
36
+ StaticTokenProvider,
37
+ )
38
+ from cc_platform_sdk.auth.exceptions import (
39
+ AuthenticationError,
40
+ InsufficientRoleError,
41
+ InsufficientScopeError,
42
+ InvalidTokenError,
43
+ JWKSError,
44
+ MissingTokenError,
45
+ TokenExpiredError,
46
+ )
47
+ from cc_platform_sdk.auth.jwks_client import JWKSClient, extract_bearer_token
48
+ from cc_platform_sdk.auth.models import (
49
+ TokenPayload,
50
+ UserClaims,
51
+ create_user_claims,
52
+ )
53
+ from cc_platform_sdk.auth.middleware import (
54
+ AuthMiddleware,
55
+ AuthMiddlewareConfig,
56
+ OutboundCredentialInterceptor,
57
+ )
58
+ from cc_platform_sdk.auth.security_identity import (
59
+ SecurityIdentity,
60
+ create_security_identity,
61
+ is_service_identity,
62
+ is_user_identity,
63
+ )
64
+
65
+ __all__ = [
66
+ # config
67
+ "AuthConfig",
68
+ "validate_config",
69
+ # models
70
+ "TokenPayload",
71
+ "UserClaims",
72
+ "create_user_claims",
73
+ # security identity
74
+ "SecurityIdentity",
75
+ "create_security_identity",
76
+ "is_service_identity",
77
+ "is_user_identity",
78
+ # credential providers
79
+ "CredentialProvider",
80
+ "CredentialResult",
81
+ "BearerTokenProvider",
82
+ "StaticTokenProvider",
83
+ "NoopCredentialProvider",
84
+ "MtlsConfig",
85
+ # jwks
86
+ "JWKSClient",
87
+ "extract_bearer_token",
88
+ # acting user
89
+ "HeaderNames",
90
+ "ActingUserContext",
91
+ "sign_acting_user_headers",
92
+ "extract_acting_user_headers",
93
+ "verify_acting_user_signature",
94
+ # middleware
95
+ "AuthMiddleware",
96
+ "AuthMiddlewareConfig",
97
+ "OutboundCredentialInterceptor",
98
+ # exceptions
99
+ "AuthenticationError",
100
+ "InvalidTokenError",
101
+ "TokenExpiredError",
102
+ "MissingTokenError",
103
+ "InsufficientScopeError",
104
+ "InsufficientRoleError",
105
+ "JWKSError",
106
+ ]