switchly 0.1.0__py3-none-any.whl

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 (102) hide show
  1. switchly/__init__.py +169 -0
  2. switchly/admin/__init__.py +11 -0
  3. switchly/admin/api.py +1190 -0
  4. switchly/admin/app.py +598 -0
  5. switchly/admin/auth.py +259 -0
  6. switchly/cli/__init__.py +0 -0
  7. switchly/cli/client.py +567 -0
  8. switchly/cli/config.py +253 -0
  9. switchly/cli/main.py +2608 -0
  10. switchly/core/__init__.py +0 -0
  11. switchly/core/backends/__init__.py +0 -0
  12. switchly/core/backends/base.py +413 -0
  13. switchly/core/backends/file.py +425 -0
  14. switchly/core/backends/memory.py +183 -0
  15. switchly/core/backends/redis.py +472 -0
  16. switchly/core/backends/server.py +794 -0
  17. switchly/core/config.py +281 -0
  18. switchly/core/engine.py +2497 -0
  19. switchly/core/exceptions.py +145 -0
  20. switchly/core/feature_flags/__init__.py +153 -0
  21. switchly/core/feature_flags/_context.py +65 -0
  22. switchly/core/feature_flags/_guard.py +26 -0
  23. switchly/core/feature_flags/client.py +171 -0
  24. switchly/core/feature_flags/evaluator.py +443 -0
  25. switchly/core/feature_flags/hooks.py +168 -0
  26. switchly/core/feature_flags/models.py +590 -0
  27. switchly/core/feature_flags/provider.py +199 -0
  28. switchly/core/feature_flags/scheduler.py +233 -0
  29. switchly/core/models.py +100 -0
  30. switchly/core/rate_limit/__init__.py +11 -0
  31. switchly/core/rate_limit/keys.py +229 -0
  32. switchly/core/rate_limit/limiter.py +250 -0
  33. switchly/core/rate_limit/models.py +324 -0
  34. switchly/core/rate_limit/storage.py +689 -0
  35. switchly/core/scheduler.py +225 -0
  36. switchly/core/webhooks.py +60 -0
  37. switchly/dashboard/__init__.py +5 -0
  38. switchly/dashboard/app.py +151 -0
  39. switchly/dashboard/auth.py +61 -0
  40. switchly/dashboard/routes.py +2161 -0
  41. switchly/dashboard/static/switchly.min.css +2 -0
  42. switchly/dashboard/templates/audit.html +90 -0
  43. switchly/dashboard/templates/base.html +689 -0
  44. switchly/dashboard/templates/flag_detail.html +773 -0
  45. switchly/dashboard/templates/flags.html +136 -0
  46. switchly/dashboard/templates/index.html +142 -0
  47. switchly/dashboard/templates/login.html +107 -0
  48. switchly/dashboard/templates/partials/audit_row.html +107 -0
  49. switchly/dashboard/templates/partials/audit_rows.html +3 -0
  50. switchly/dashboard/templates/partials/flag_eval_result.html +137 -0
  51. switchly/dashboard/templates/partials/flag_row.html +131 -0
  52. switchly/dashboard/templates/partials/flag_rows.html +34 -0
  53. switchly/dashboard/templates/partials/global_maintenance.html +79 -0
  54. switchly/dashboard/templates/partials/global_rl_card.html +133 -0
  55. switchly/dashboard/templates/partials/modal.html +115 -0
  56. switchly/dashboard/templates/partials/modal_env_gate.html +71 -0
  57. switchly/dashboard/templates/partials/modal_flag_create.html +105 -0
  58. switchly/dashboard/templates/partials/modal_flag_eval.html +112 -0
  59. switchly/dashboard/templates/partials/modal_global_disable.html +51 -0
  60. switchly/dashboard/templates/partials/modal_global_enable.html +114 -0
  61. switchly/dashboard/templates/partials/modal_global_rl.html +129 -0
  62. switchly/dashboard/templates/partials/modal_global_rl_delete.html +39 -0
  63. switchly/dashboard/templates/partials/modal_global_rl_reset.html +39 -0
  64. switchly/dashboard/templates/partials/modal_rl_add.html +120 -0
  65. switchly/dashboard/templates/partials/modal_rl_delete.html +56 -0
  66. switchly/dashboard/templates/partials/modal_rl_edit.html +109 -0
  67. switchly/dashboard/templates/partials/modal_rl_reset.html +45 -0
  68. switchly/dashboard/templates/partials/modal_segment_create.html +86 -0
  69. switchly/dashboard/templates/partials/modal_segment_detail.html +118 -0
  70. switchly/dashboard/templates/partials/modal_segment_view.html +151 -0
  71. switchly/dashboard/templates/partials/modal_service_disable.html +51 -0
  72. switchly/dashboard/templates/partials/modal_service_enable.html +95 -0
  73. switchly/dashboard/templates/partials/modal_service_rl.html +131 -0
  74. switchly/dashboard/templates/partials/modal_service_rl_delete.html +41 -0
  75. switchly/dashboard/templates/partials/modal_service_rl_reset.html +41 -0
  76. switchly/dashboard/templates/partials/pagination.html +63 -0
  77. switchly/dashboard/templates/partials/rate_limit_hits.html +16 -0
  78. switchly/dashboard/templates/partials/rate_limit_rows.html +61 -0
  79. switchly/dashboard/templates/partials/route_row.html +179 -0
  80. switchly/dashboard/templates/partials/routes_table.html +4 -0
  81. switchly/dashboard/templates/partials/segment_row.html +96 -0
  82. switchly/dashboard/templates/partials/segment_rows.html +34 -0
  83. switchly/dashboard/templates/partials/segment_rules_section.html +172 -0
  84. switchly/dashboard/templates/partials/service_maintenance.html +75 -0
  85. switchly/dashboard/templates/partials/service_rl_card.html +135 -0
  86. switchly/dashboard/templates/rate_limits.html +166 -0
  87. switchly/dashboard/templates/rl_hits.html +50 -0
  88. switchly/dashboard/templates/segments.html +112 -0
  89. switchly/fastapi/__init__.py +51 -0
  90. switchly/fastapi/decorators.py +762 -0
  91. switchly/fastapi/dependencies.py +123 -0
  92. switchly/fastapi/middleware.py +506 -0
  93. switchly/fastapi/openapi.py +633 -0
  94. switchly/fastapi/router.py +250 -0
  95. switchly/sdk/__init__.py +254 -0
  96. switchly/sdk/flag_provider.py +176 -0
  97. switchly/server/__init__.py +115 -0
  98. switchly-0.1.0.dist-info/METADATA +427 -0
  99. switchly-0.1.0.dist-info/RECORD +102 -0
  100. switchly-0.1.0.dist-info/WHEEL +4 -0
  101. switchly-0.1.0.dist-info/entry_points.txt +2 -0
  102. switchly-0.1.0.dist-info/licenses/LICENSE +21 -0
switchly/__init__.py ADDED
@@ -0,0 +1,169 @@
1
+ """switchly — route lifecycle management for Python APIs.
2
+
3
+ All public symbols are available directly from this package::
4
+
5
+ from switchly import (
6
+ SwitchlyEngine,
7
+ make_engine,
8
+ MemoryBackend,
9
+ FileBackend,
10
+ RouteState,
11
+ AuditEntry,
12
+ MaintenanceWindow,
13
+ RateLimitPolicy,
14
+ SwitchlyException,
15
+ SlackWebhookFormatter,
16
+ default_formatter,
17
+ # feature flag models (requires switchly[flags])
18
+ FeatureFlag,
19
+ EvaluationContext,
20
+ )
21
+
22
+ Framework adapters live in their own namespaces::
23
+
24
+ from switchly.fastapi import SwitchlyAdmin, SwitchlyMiddleware, SwitchlyRouter, ...
25
+ from switchly.sdk import SwitchlySDK
26
+ from switchly.server import SwitchlyServer
27
+ """
28
+
29
+ # ---------------------------------------------------------------------------
30
+ # Engine & config
31
+ # ---------------------------------------------------------------------------
32
+ # ---------------------------------------------------------------------------
33
+ # Backends
34
+ # ---------------------------------------------------------------------------
35
+ from switchly.core.backends.base import SwitchlyBackend
36
+ from switchly.core.backends.file import FileBackend
37
+ from switchly.core.backends.memory import MemoryBackend
38
+ from switchly.core.config import make_backend, make_engine
39
+ from switchly.core.engine import SwitchlyEngine
40
+
41
+ # ---------------------------------------------------------------------------
42
+ # Exceptions
43
+ # ---------------------------------------------------------------------------
44
+ from switchly.core.exceptions import (
45
+ AmbiguousRouteError,
46
+ EnvGatedException,
47
+ MaintenanceException,
48
+ RateLimitExceededException,
49
+ RouteDisabledException,
50
+ RouteNotFoundException,
51
+ RouteProtectedException,
52
+ SwitchlyException,
53
+ SwitchlyProductionWarning,
54
+ )
55
+
56
+ # ---------------------------------------------------------------------------
57
+ # Feature flag models (pure Pydantic — safe without the [flags] extra)
58
+ # ---------------------------------------------------------------------------
59
+ from switchly.core.feature_flags.evaluator import FlagEvaluator
60
+ from switchly.core.feature_flags.models import (
61
+ EvaluationContext,
62
+ EvaluationReason,
63
+ FeatureFlag,
64
+ FlagStatus,
65
+ FlagType,
66
+ FlagVariation,
67
+ Operator,
68
+ Prerequisite,
69
+ ResolutionDetails,
70
+ RolloutVariation,
71
+ RuleClause,
72
+ Segment,
73
+ SegmentRule,
74
+ TargetingRule,
75
+ )
76
+
77
+ # ---------------------------------------------------------------------------
78
+ # Models
79
+ # ---------------------------------------------------------------------------
80
+ from switchly.core.models import (
81
+ AuditEntry,
82
+ GlobalMaintenanceConfig,
83
+ MaintenanceWindow,
84
+ RouteState,
85
+ RouteStatus,
86
+ )
87
+
88
+ # ---------------------------------------------------------------------------
89
+ # Rate limiting models
90
+ # ---------------------------------------------------------------------------
91
+ from switchly.core.rate_limit.models import (
92
+ GlobalRateLimitPolicy,
93
+ OnMissingKey,
94
+ RateLimitAlgorithm,
95
+ RateLimitHit,
96
+ RateLimitKeyStrategy,
97
+ RateLimitPolicy,
98
+ RateLimitResult,
99
+ RateLimitTier,
100
+ )
101
+
102
+ # ---------------------------------------------------------------------------
103
+ # Webhooks
104
+ # ---------------------------------------------------------------------------
105
+ from switchly.core.webhooks import SlackWebhookFormatter, default_formatter
106
+
107
+ # ---------------------------------------------------------------------------
108
+ # RedisBackend — available only when the [redis] extra is installed
109
+ # ---------------------------------------------------------------------------
110
+ try:
111
+ from switchly.core.backends.redis import RedisBackend
112
+ except ImportError:
113
+ pass
114
+
115
+ __all__ = [
116
+ # Engine & config
117
+ "SwitchlyEngine",
118
+ "make_engine",
119
+ "make_backend",
120
+ # Backends
121
+ "SwitchlyBackend",
122
+ "MemoryBackend",
123
+ "FileBackend",
124
+ "RedisBackend",
125
+ # Models
126
+ "RouteStatus",
127
+ "RouteState",
128
+ "AuditEntry",
129
+ "MaintenanceWindow",
130
+ "GlobalMaintenanceConfig",
131
+ # Exceptions
132
+ "SwitchlyException",
133
+ "MaintenanceException",
134
+ "EnvGatedException",
135
+ "RouteDisabledException",
136
+ "RouteNotFoundException",
137
+ "AmbiguousRouteError",
138
+ "RouteProtectedException",
139
+ "RateLimitExceededException",
140
+ "SwitchlyProductionWarning",
141
+ # Webhooks
142
+ "default_formatter",
143
+ "SlackWebhookFormatter",
144
+ # Rate limiting
145
+ "RateLimitAlgorithm",
146
+ "OnMissingKey",
147
+ "RateLimitKeyStrategy",
148
+ "RateLimitTier",
149
+ "RateLimitPolicy",
150
+ "RateLimitResult",
151
+ "GlobalRateLimitPolicy",
152
+ "RateLimitHit",
153
+ # Feature flags
154
+ "FlagEvaluator",
155
+ "EvaluationContext",
156
+ "EvaluationReason",
157
+ "FeatureFlag",
158
+ "FlagStatus",
159
+ "FlagType",
160
+ "FlagVariation",
161
+ "Operator",
162
+ "Prerequisite",
163
+ "ResolutionDetails",
164
+ "RolloutVariation",
165
+ "RuleClause",
166
+ "Segment",
167
+ "SegmentRule",
168
+ "TargetingRule",
169
+ ]
@@ -0,0 +1,11 @@
1
+ """Switchly Admin — unified admin interface for switchly.
2
+
3
+ Exposes both the HTMX dashboard UI *and* a REST API that the ``switchly`` CLI
4
+ uses as its HTTP back-end. Mount a single :func:`SwitchlyAdmin` instance on
5
+ your FastAPI / Starlette application and both interfaces are available
6
+ immediately.
7
+ """
8
+
9
+ from switchly.admin.app import SwitchlyAdmin
10
+
11
+ __all__ = ["SwitchlyAdmin"]