svc-infra 0.1.595__py3-none-any.whl โ†’ 1.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.

Potentially problematic release.


This version of svc-infra might be problematic. Click here for more details.

Files changed (274) hide show
  1. svc_infra/__init__.py +58 -2
  2. svc_infra/apf_payments/models.py +68 -38
  3. svc_infra/apf_payments/provider/__init__.py +2 -2
  4. svc_infra/apf_payments/provider/aiydan.py +39 -23
  5. svc_infra/apf_payments/provider/base.py +8 -3
  6. svc_infra/apf_payments/provider/registry.py +3 -5
  7. svc_infra/apf_payments/provider/stripe.py +74 -52
  8. svc_infra/apf_payments/schemas.py +84 -83
  9. svc_infra/apf_payments/service.py +27 -16
  10. svc_infra/apf_payments/settings.py +12 -11
  11. svc_infra/api/__init__.py +61 -0
  12. svc_infra/api/fastapi/__init__.py +34 -0
  13. svc_infra/api/fastapi/admin/__init__.py +3 -0
  14. svc_infra/api/fastapi/admin/add.py +240 -0
  15. svc_infra/api/fastapi/apf_payments/router.py +94 -73
  16. svc_infra/api/fastapi/apf_payments/setup.py +10 -9
  17. svc_infra/api/fastapi/auth/__init__.py +65 -0
  18. svc_infra/api/fastapi/auth/_cookies.py +1 -3
  19. svc_infra/api/fastapi/auth/add.py +14 -15
  20. svc_infra/api/fastapi/auth/gaurd.py +32 -20
  21. svc_infra/api/fastapi/auth/mfa/models.py +3 -4
  22. svc_infra/api/fastapi/auth/mfa/pre_auth.py +13 -9
  23. svc_infra/api/fastapi/auth/mfa/router.py +9 -8
  24. svc_infra/api/fastapi/auth/mfa/security.py +4 -7
  25. svc_infra/api/fastapi/auth/mfa/utils.py +5 -3
  26. svc_infra/api/fastapi/auth/policy.py +0 -1
  27. svc_infra/api/fastapi/auth/providers.py +3 -3
  28. svc_infra/api/fastapi/auth/routers/apikey_router.py +19 -21
  29. svc_infra/api/fastapi/auth/routers/oauth_router.py +98 -52
  30. svc_infra/api/fastapi/auth/routers/session_router.py +6 -5
  31. svc_infra/api/fastapi/auth/security.py +25 -15
  32. svc_infra/api/fastapi/auth/sender.py +5 -0
  33. svc_infra/api/fastapi/auth/settings.py +18 -19
  34. svc_infra/api/fastapi/auth/state.py +5 -4
  35. svc_infra/api/fastapi/auth/ws_security.py +275 -0
  36. svc_infra/api/fastapi/billing/router.py +71 -0
  37. svc_infra/api/fastapi/billing/setup.py +19 -0
  38. svc_infra/api/fastapi/cache/add.py +9 -5
  39. svc_infra/api/fastapi/db/__init__.py +5 -1
  40. svc_infra/api/fastapi/db/http.py +10 -9
  41. svc_infra/api/fastapi/db/nosql/__init__.py +39 -1
  42. svc_infra/api/fastapi/db/nosql/mongo/add.py +35 -30
  43. svc_infra/api/fastapi/db/nosql/mongo/crud_router.py +39 -21
  44. svc_infra/api/fastapi/db/sql/__init__.py +5 -1
  45. svc_infra/api/fastapi/db/sql/add.py +62 -25
  46. svc_infra/api/fastapi/db/sql/crud_router.py +205 -30
  47. svc_infra/api/fastapi/db/sql/session.py +19 -2
  48. svc_infra/api/fastapi/db/sql/users.py +18 -9
  49. svc_infra/api/fastapi/dependencies/ratelimit.py +76 -14
  50. svc_infra/api/fastapi/docs/add.py +163 -0
  51. svc_infra/api/fastapi/docs/landing.py +6 -6
  52. svc_infra/api/fastapi/docs/scoped.py +75 -36
  53. svc_infra/api/fastapi/dual/__init__.py +12 -2
  54. svc_infra/api/fastapi/dual/dualize.py +2 -2
  55. svc_infra/api/fastapi/dual/protected.py +123 -10
  56. svc_infra/api/fastapi/dual/public.py +25 -0
  57. svc_infra/api/fastapi/dual/router.py +18 -8
  58. svc_infra/api/fastapi/dx.py +33 -2
  59. svc_infra/api/fastapi/ease.py +59 -7
  60. svc_infra/api/fastapi/http/concurrency.py +2 -1
  61. svc_infra/api/fastapi/http/conditional.py +2 -2
  62. svc_infra/api/fastapi/middleware/debug.py +4 -1
  63. svc_infra/api/fastapi/middleware/errors/exceptions.py +2 -5
  64. svc_infra/api/fastapi/middleware/errors/handlers.py +50 -10
  65. svc_infra/api/fastapi/middleware/graceful_shutdown.py +95 -0
  66. svc_infra/api/fastapi/middleware/idempotency.py +190 -68
  67. svc_infra/api/fastapi/middleware/idempotency_store.py +187 -0
  68. svc_infra/api/fastapi/middleware/optimistic_lock.py +39 -0
  69. svc_infra/api/fastapi/middleware/ratelimit.py +125 -28
  70. svc_infra/api/fastapi/middleware/ratelimit_store.py +45 -13
  71. svc_infra/api/fastapi/middleware/request_id.py +24 -10
  72. svc_infra/api/fastapi/middleware/request_size_limit.py +3 -3
  73. svc_infra/api/fastapi/middleware/timeout.py +176 -0
  74. svc_infra/api/fastapi/object_router.py +1060 -0
  75. svc_infra/api/fastapi/openapi/apply.py +4 -3
  76. svc_infra/api/fastapi/openapi/conventions.py +13 -6
  77. svc_infra/api/fastapi/openapi/mutators.py +144 -17
  78. svc_infra/api/fastapi/openapi/pipeline.py +2 -2
  79. svc_infra/api/fastapi/openapi/responses.py +4 -6
  80. svc_infra/api/fastapi/openapi/security.py +1 -1
  81. svc_infra/api/fastapi/ops/add.py +73 -0
  82. svc_infra/api/fastapi/pagination.py +47 -32
  83. svc_infra/api/fastapi/routers/__init__.py +16 -10
  84. svc_infra/api/fastapi/routers/ping.py +1 -0
  85. svc_infra/api/fastapi/setup.py +167 -54
  86. svc_infra/api/fastapi/tenancy/add.py +20 -0
  87. svc_infra/api/fastapi/tenancy/context.py +113 -0
  88. svc_infra/api/fastapi/versioned.py +102 -0
  89. svc_infra/app/README.md +5 -5
  90. svc_infra/app/__init__.py +3 -1
  91. svc_infra/app/env.py +70 -4
  92. svc_infra/app/logging/add.py +10 -2
  93. svc_infra/app/logging/filter.py +1 -1
  94. svc_infra/app/logging/formats.py +13 -5
  95. svc_infra/app/root.py +3 -3
  96. svc_infra/billing/__init__.py +40 -0
  97. svc_infra/billing/async_service.py +167 -0
  98. svc_infra/billing/jobs.py +231 -0
  99. svc_infra/billing/models.py +146 -0
  100. svc_infra/billing/quotas.py +101 -0
  101. svc_infra/billing/schemas.py +34 -0
  102. svc_infra/bundled_docs/README.md +5 -0
  103. svc_infra/bundled_docs/__init__.py +1 -0
  104. svc_infra/bundled_docs/getting-started.md +6 -0
  105. svc_infra/cache/__init__.py +21 -5
  106. svc_infra/cache/add.py +167 -0
  107. svc_infra/cache/backend.py +9 -7
  108. svc_infra/cache/decorators.py +75 -20
  109. svc_infra/cache/demo.py +2 -2
  110. svc_infra/cache/keys.py +26 -6
  111. svc_infra/cache/recache.py +26 -27
  112. svc_infra/cache/resources.py +6 -5
  113. svc_infra/cache/tags.py +19 -44
  114. svc_infra/cache/ttl.py +2 -3
  115. svc_infra/cache/utils.py +4 -3
  116. svc_infra/cli/__init__.py +44 -8
  117. svc_infra/cli/__main__.py +4 -0
  118. svc_infra/cli/cmds/__init__.py +39 -2
  119. svc_infra/cli/cmds/db/nosql/mongo/mongo_cmds.py +18 -14
  120. svc_infra/cli/cmds/db/nosql/mongo/mongo_scaffold_cmds.py +9 -10
  121. svc_infra/cli/cmds/db/ops_cmds.py +267 -0
  122. svc_infra/cli/cmds/db/sql/alembic_cmds.py +97 -29
  123. svc_infra/cli/cmds/db/sql/sql_export_cmds.py +80 -0
  124. svc_infra/cli/cmds/db/sql/sql_scaffold_cmds.py +13 -13
  125. svc_infra/cli/cmds/docs/docs_cmds.py +139 -0
  126. svc_infra/cli/cmds/dx/__init__.py +12 -0
  127. svc_infra/cli/cmds/dx/dx_cmds.py +110 -0
  128. svc_infra/cli/cmds/health/__init__.py +179 -0
  129. svc_infra/cli/cmds/health/health_cmds.py +8 -0
  130. svc_infra/cli/cmds/help.py +4 -0
  131. svc_infra/cli/cmds/jobs/__init__.py +1 -0
  132. svc_infra/cli/cmds/jobs/jobs_cmds.py +42 -0
  133. svc_infra/cli/cmds/obs/obs_cmds.py +31 -13
  134. svc_infra/cli/cmds/sdk/__init__.py +0 -0
  135. svc_infra/cli/cmds/sdk/sdk_cmds.py +102 -0
  136. svc_infra/cli/foundation/runner.py +4 -5
  137. svc_infra/cli/foundation/typer_bootstrap.py +1 -2
  138. svc_infra/data/__init__.py +83 -0
  139. svc_infra/data/add.py +61 -0
  140. svc_infra/data/backup.py +56 -0
  141. svc_infra/data/erasure.py +46 -0
  142. svc_infra/data/fixtures.py +42 -0
  143. svc_infra/data/retention.py +56 -0
  144. svc_infra/db/__init__.py +15 -0
  145. svc_infra/db/crud_schema.py +14 -13
  146. svc_infra/db/inbox.py +67 -0
  147. svc_infra/db/nosql/__init__.py +2 -0
  148. svc_infra/db/nosql/constants.py +1 -1
  149. svc_infra/db/nosql/core.py +19 -5
  150. svc_infra/db/nosql/indexes.py +12 -9
  151. svc_infra/db/nosql/management.py +4 -4
  152. svc_infra/db/nosql/mongo/README.md +13 -13
  153. svc_infra/db/nosql/mongo/client.py +21 -4
  154. svc_infra/db/nosql/mongo/settings.py +1 -1
  155. svc_infra/db/nosql/repository.py +46 -27
  156. svc_infra/db/nosql/resource.py +28 -16
  157. svc_infra/db/nosql/scaffold.py +14 -12
  158. svc_infra/db/nosql/service.py +2 -1
  159. svc_infra/db/nosql/service_with_hooks.py +4 -3
  160. svc_infra/db/nosql/utils.py +4 -4
  161. svc_infra/db/ops.py +380 -0
  162. svc_infra/db/outbox.py +105 -0
  163. svc_infra/db/sql/apikey.py +34 -15
  164. svc_infra/db/sql/authref.py +8 -6
  165. svc_infra/db/sql/constants.py +5 -1
  166. svc_infra/db/sql/core.py +13 -13
  167. svc_infra/db/sql/management.py +5 -6
  168. svc_infra/db/sql/repository.py +92 -26
  169. svc_infra/db/sql/resource.py +18 -12
  170. svc_infra/db/sql/scaffold.py +11 -11
  171. svc_infra/db/sql/service.py +2 -1
  172. svc_infra/db/sql/service_with_hooks.py +4 -3
  173. svc_infra/db/sql/templates/models_schemas/auth/models.py.tmpl +7 -56
  174. svc_infra/db/sql/templates/setup/env_async.py.tmpl +34 -12
  175. svc_infra/db/sql/templates/setup/env_sync.py.tmpl +29 -7
  176. svc_infra/db/sql/tenant.py +80 -0
  177. svc_infra/db/sql/uniq.py +8 -7
  178. svc_infra/db/sql/uniq_hooks.py +12 -11
  179. svc_infra/db/sql/utils.py +105 -47
  180. svc_infra/db/sql/versioning.py +14 -0
  181. svc_infra/db/utils.py +3 -3
  182. svc_infra/deploy/__init__.py +531 -0
  183. svc_infra/documents/__init__.py +100 -0
  184. svc_infra/documents/add.py +263 -0
  185. svc_infra/documents/ease.py +233 -0
  186. svc_infra/documents/models.py +114 -0
  187. svc_infra/documents/storage.py +262 -0
  188. svc_infra/dx/__init__.py +58 -0
  189. svc_infra/dx/add.py +63 -0
  190. svc_infra/dx/changelog.py +74 -0
  191. svc_infra/dx/checks.py +68 -0
  192. svc_infra/exceptions.py +141 -0
  193. svc_infra/health/__init__.py +863 -0
  194. svc_infra/http/__init__.py +13 -0
  195. svc_infra/http/client.py +101 -0
  196. svc_infra/jobs/__init__.py +79 -0
  197. svc_infra/jobs/builtins/outbox_processor.py +38 -0
  198. svc_infra/jobs/builtins/webhook_delivery.py +93 -0
  199. svc_infra/jobs/easy.py +33 -0
  200. svc_infra/jobs/loader.py +49 -0
  201. svc_infra/jobs/queue.py +106 -0
  202. svc_infra/jobs/redis_queue.py +242 -0
  203. svc_infra/jobs/runner.py +75 -0
  204. svc_infra/jobs/scheduler.py +53 -0
  205. svc_infra/jobs/worker.py +40 -0
  206. svc_infra/loaders/__init__.py +186 -0
  207. svc_infra/loaders/base.py +143 -0
  208. svc_infra/loaders/github.py +309 -0
  209. svc_infra/loaders/models.py +147 -0
  210. svc_infra/loaders/url.py +229 -0
  211. svc_infra/logging/__init__.py +375 -0
  212. svc_infra/mcp/__init__.py +82 -0
  213. svc_infra/mcp/svc_infra_mcp.py +91 -33
  214. svc_infra/obs/README.md +2 -0
  215. svc_infra/obs/add.py +68 -11
  216. svc_infra/obs/cloud_dash.py +2 -1
  217. svc_infra/obs/grafana/dashboards/http-overview.json +45 -0
  218. svc_infra/obs/metrics/__init__.py +6 -7
  219. svc_infra/obs/metrics/asgi.py +8 -7
  220. svc_infra/obs/metrics/base.py +13 -13
  221. svc_infra/obs/metrics/http.py +3 -3
  222. svc_infra/obs/metrics/sqlalchemy.py +14 -13
  223. svc_infra/obs/metrics.py +9 -8
  224. svc_infra/resilience/__init__.py +44 -0
  225. svc_infra/resilience/circuit_breaker.py +328 -0
  226. svc_infra/resilience/retry.py +289 -0
  227. svc_infra/security/__init__.py +167 -0
  228. svc_infra/security/add.py +213 -0
  229. svc_infra/security/audit.py +97 -18
  230. svc_infra/security/audit_service.py +10 -9
  231. svc_infra/security/headers.py +15 -2
  232. svc_infra/security/hibp.py +14 -7
  233. svc_infra/security/jwt_rotation.py +78 -29
  234. svc_infra/security/lockout.py +23 -16
  235. svc_infra/security/models.py +77 -44
  236. svc_infra/security/oauth_models.py +73 -0
  237. svc_infra/security/org_invites.py +12 -12
  238. svc_infra/security/passwords.py +3 -3
  239. svc_infra/security/permissions.py +31 -7
  240. svc_infra/security/session.py +7 -8
  241. svc_infra/security/signed_cookies.py +26 -6
  242. svc_infra/storage/__init__.py +93 -0
  243. svc_infra/storage/add.py +250 -0
  244. svc_infra/storage/backends/__init__.py +11 -0
  245. svc_infra/storage/backends/local.py +331 -0
  246. svc_infra/storage/backends/memory.py +213 -0
  247. svc_infra/storage/backends/s3.py +334 -0
  248. svc_infra/storage/base.py +239 -0
  249. svc_infra/storage/easy.py +181 -0
  250. svc_infra/storage/settings.py +193 -0
  251. svc_infra/testing/__init__.py +682 -0
  252. svc_infra/utils.py +170 -5
  253. svc_infra/webhooks/__init__.py +69 -0
  254. svc_infra/webhooks/add.py +327 -0
  255. svc_infra/webhooks/encryption.py +115 -0
  256. svc_infra/webhooks/fastapi.py +37 -0
  257. svc_infra/webhooks/router.py +55 -0
  258. svc_infra/webhooks/service.py +69 -0
  259. svc_infra/webhooks/signing.py +34 -0
  260. svc_infra/websocket/__init__.py +79 -0
  261. svc_infra/websocket/add.py +139 -0
  262. svc_infra/websocket/client.py +283 -0
  263. svc_infra/websocket/config.py +57 -0
  264. svc_infra/websocket/easy.py +76 -0
  265. svc_infra/websocket/exceptions.py +61 -0
  266. svc_infra/websocket/manager.py +343 -0
  267. svc_infra/websocket/models.py +49 -0
  268. svc_infra-1.1.0.dist-info/LICENSE +21 -0
  269. svc_infra-1.1.0.dist-info/METADATA +362 -0
  270. svc_infra-1.1.0.dist-info/RECORD +364 -0
  271. svc_infra-0.1.595.dist-info/METADATA +0 -80
  272. svc_infra-0.1.595.dist-info/RECORD +0 -253
  273. {svc_infra-0.1.595.dist-info โ†’ svc_infra-1.1.0.dist-info}/WHEEL +0 -0
  274. {svc_infra-0.1.595.dist-info โ†’ svc_infra-1.1.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,362 @@
1
+ Metadata-Version: 2.3
2
+ Name: svc-infra
3
+ Version: 1.1.0
4
+ Summary: Infrastructure for building and deploying prod-ready services
5
+ License: MIT
6
+ Keywords: fastapi,sqlalchemy,alembic,auth,infra,async,pydantic
7
+ Author: Ali Khatami
8
+ Author-email: aliikhatami94@gmail.com
9
+ Requires-Python: >=3.11,<4.0
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Framework :: FastAPI
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Typing :: Typed
22
+ Provides-Extra: adyen
23
+ Provides-Extra: duckdb
24
+ Provides-Extra: metrics
25
+ Provides-Extra: mongodb
26
+ Provides-Extra: mssql
27
+ Provides-Extra: mysql
28
+ Provides-Extra: payments
29
+ Provides-Extra: pg
30
+ Provides-Extra: pg2
31
+ Provides-Extra: redshift
32
+ Provides-Extra: s3
33
+ Provides-Extra: snowflake
34
+ Provides-Extra: sqlite
35
+ Provides-Extra: stripe
36
+ Requires-Dist: adyen (>=10.0.0) ; extra == "payments" or extra == "adyen"
37
+ Requires-Dist: aioboto3 (>=12.0.0) ; extra == "s3"
38
+ Requires-Dist: aiofiles (>=24.0.0)
39
+ Requires-Dist: aiosqlite (>=0.19.0) ; extra == "sqlite"
40
+ Requires-Dist: alembic (>=1.13.0)
41
+ Requires-Dist: asyncpg (>=0.29.0) ; extra == "pg"
42
+ Requires-Dist: authlib (>=1.0.0)
43
+ Requires-Dist: cashews[redis] (>=7.0)
44
+ Requires-Dist: duckdb (>=0.10.0) ; extra == "duckdb"
45
+ Requires-Dist: email-validator (>=2.0.0)
46
+ Requires-Dist: fastapi (>=0.110.0)
47
+ Requires-Dist: fastapi-users-db-sqlalchemy (>=7.0.0)
48
+ Requires-Dist: fastapi-users[oauth] (>=14.0.0)
49
+ Requires-Dist: greenlet (>=3.0)
50
+ Requires-Dist: httpx (>=0.25.0)
51
+ Requires-Dist: httpx-oauth (>=0.15.0)
52
+ Requires-Dist: itsdangerous (>=2.0.0)
53
+ Requires-Dist: mcp (>=1.0.0)
54
+ Requires-Dist: motor (>=3.0.0) ; extra == "mongodb"
55
+ Requires-Dist: mysqlclient (>=2.2.0) ; extra == "mysql"
56
+ Requires-Dist: opentelemetry-exporter-otlp (>=1.20.0)
57
+ Requires-Dist: opentelemetry-instrumentation-fastapi (>=0.41b0)
58
+ Requires-Dist: opentelemetry-instrumentation-httpx (>=0.41b0)
59
+ Requires-Dist: opentelemetry-instrumentation-requests (>=0.41b0)
60
+ Requires-Dist: opentelemetry-instrumentation-sqlalchemy (>=0.41b0)
61
+ Requires-Dist: opentelemetry-propagator-b3 (>=1.20.0)
62
+ Requires-Dist: opentelemetry-sdk (>=1.20.0)
63
+ Requires-Dist: passlib[bcrypt] (>=1.7.4)
64
+ Requires-Dist: prometheus-client (>=0.18.0) ; extra == "metrics"
65
+ Requires-Dist: psycopg2-binary (>=2.9.0) ; extra == "pg2"
66
+ Requires-Dist: psycopg[binary] (>=3.0) ; extra == "pg"
67
+ Requires-Dist: pydantic-settings (>=2.0)
68
+ Requires-Dist: pymysql (>=1.1.0) ; extra == "mysql"
69
+ Requires-Dist: pyodbc (>=5.0.0) ; extra == "mssql"
70
+ Requires-Dist: pyotp (>=2.9.0)
71
+ Requires-Dist: python-dotenv (>=1.0.0)
72
+ Requires-Dist: redis (>=5.0.0)
73
+ Requires-Dist: redshift-connector (>=2.0.0) ; extra == "redshift"
74
+ Requires-Dist: snowflake-connector-python (>=3.0.0) ; extra == "snowflake"
75
+ Requires-Dist: sqlalchemy[asyncio] (>=2.0)
76
+ Requires-Dist: stripe (>=7.0.0) ; extra == "payments" or extra == "stripe"
77
+ Requires-Dist: typer (>=0.12.0)
78
+ Requires-Dist: websockets (>=12.0)
79
+ Project-URL: Documentation, https://nfrax.com/svc-infra
80
+ Project-URL: Homepage, https://github.com/nfraxlab/svc-infra
81
+ Project-URL: Issues, https://github.com/nfraxlab/svc-infra/issues
82
+ Project-URL: Repository, https://github.com/nfraxlab/svc-infra
83
+ Description-Content-Type: text/markdown
84
+
85
+ <div align="center">
86
+
87
+ # svc-infra
88
+
89
+ [![v1.0.0](https://img.shields.io/badge/version-1.0.0-green.svg)](CHANGELOG.md)
90
+ [![CI](https://github.com/nfraxlab/svc-infra/actions/workflows/ci.yml/badge.svg)](https://github.com/nfraxlab/svc-infra/actions/workflows/ci.yml)
91
+ [![PyPI](https://img.shields.io/pypi/v/svc-infra.svg)](https://pypi.org/project/svc-infra/)
92
+ [![Python](https://img.shields.io/pypi/pyversions/svc-infra.svg)](https://pypi.org/project/svc-infra/)
93
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
94
+ [![Downloads](https://img.shields.io/pypi/dm/svc-infra.svg)](https://pypi.org/project/svc-infra/)
95
+ [![codecov](https://codecov.io/gh/nfraxlab/svc-infra/branch/main/graph/badge.svg)](https://codecov.io/gh/nfraxlab/svc-infra)
96
+
97
+ ### Production-ready FastAPI infrastructure in one import
98
+
99
+ **Stop rebuilding auth, billing, webhooks, and background jobs for every project.**
100
+
101
+ [Documentation](docs/) ยท [Examples](examples/) ยท [PyPI](https://pypi.org/project/svc-infra/) ยท [Changelog](CHANGELOG.md)
102
+
103
+ </div>
104
+
105
+ ---
106
+
107
+ ## Why svc-infra?
108
+
109
+ Every FastAPI project needs the same things: authentication, database setup, background jobs, caching, webhooks, billing... You've written this code before. Multiple times.
110
+
111
+ **svc-infra** packages battle-tested infrastructure used in production, so you can focus on your actual product:
112
+
113
+ ```python
114
+ from svc_infra.api.fastapi.ease import easy_service_app
115
+
116
+ app = easy_service_app(name="MyAPI", release="1.0.0")
117
+ # โœ… Health checks, CORS, security headers, structured logging
118
+ # โœ… Prometheus metrics, OpenTelemetry tracing
119
+ # โœ… Request IDs, idempotency middleware
120
+ # That's it. Ship it.
121
+ ```
122
+
123
+ ## โšก Quick Install
124
+
125
+ ```bash
126
+ pip install svc-infra
127
+ ```
128
+
129
+ ## ๐ŸŽฏ What's Included
130
+
131
+ | Feature | What You Get | One-liner |
132
+ |---------|-------------|-----------|
133
+ | **๐Ÿ” Auth** | JWT, sessions, OAuth/OIDC, MFA, API keys | `add_auth_users(app)` |
134
+ | **๐Ÿ’ณ Billing** | Usage tracking, subscriptions, invoices, Stripe sync | `add_billing(app)` |
135
+ | **๐Ÿ“ฆ Database** | PostgreSQL + MongoDB, migrations, inbox/outbox | `add_sql_db(app)` |
136
+ | **โšก Jobs** | Background tasks, scheduling, retries, DLQ | `easy_jobs()` |
137
+ | **๐Ÿ”— Webhooks** | Subscriptions, HMAC signing, delivery retries | `add_webhooks(app)` |
138
+ | **๐Ÿ’พ Cache** | Redis/memory, decorators, namespacing | `init_cache()` |
139
+ | **๐Ÿ“Š Observability** | Prometheus, Grafana dashboards, OTEL | Built-in |
140
+ | **๐Ÿ“ Storage** | S3, local, memory backends | `add_storage(app)` |
141
+ | **๐Ÿข Multi-tenancy** | Tenant isolation, scoped queries | Built-in |
142
+ | **๐Ÿšฆ Rate Limiting** | Per-user, per-endpoint, headers | Built-in |
143
+
144
+ ## ๐Ÿš€ 30-Second Example
145
+
146
+ Build a complete SaaS backend:
147
+
148
+ ```python
149
+ from fastapi import Depends
150
+ from svc_infra.api.fastapi.ease import easy_service_app
151
+ from svc_infra.api.fastapi.db.sql.add import add_sql_db
152
+ from svc_infra.api.fastapi.auth import add_auth_users, current_active_user
153
+ from svc_infra.jobs.easy import easy_jobs
154
+ from svc_infra.webhooks.fastapi import require_signature
155
+
156
+ # Create app with batteries included
157
+ app = easy_service_app(name="MySaaS", release="1.0.0")
158
+
159
+ # Add infrastructure
160
+ add_sql_db(app) # PostgreSQL with migrations
161
+ add_auth_users(app) # Full auth system
162
+ queue, scheduler = easy_jobs() # Background jobs
163
+
164
+ # Your actual business logic
165
+ @app.post("/api/process")
166
+ async def process_data(user=Depends(current_active_user)):
167
+ job = queue.enqueue("heavy_task", {"user_id": user.id})
168
+ return {"job_id": job.id, "status": "queued"}
169
+
170
+ # Webhook endpoint with signature verification
171
+ @app.post("/webhooks/stripe")
172
+ async def stripe_webhook(payload=Depends(require_signature(lambda: ["whsec_..."]))):
173
+ queue.enqueue("process_payment", payload)
174
+ return {"received": True}
175
+ ```
176
+
177
+ **That's a production-ready API** with auth, database, background jobs, and webhook handling.
178
+
179
+ ## ๐Ÿ“š Feature Highlights
180
+
181
+ ### ๐Ÿ” Authentication & Security
182
+
183
+ Full auth system with zero boilerplate:
184
+
185
+ ```python
186
+ from svc_infra.api.fastapi.auth import add_auth_users, current_active_user
187
+
188
+ add_auth_users(app) # Registers /auth/* routes automatically
189
+
190
+ @app.get("/me")
191
+ async def get_profile(user=Depends(current_active_user)):
192
+ return {"email": user.email, "mfa_enabled": user.mfa_enabled}
193
+ ```
194
+
195
+ **Includes:** JWT tokens, session cookies, OAuth/OIDC (Google, GitHub, etc.), MFA/TOTP, password policies, account lockout, key rotation.
196
+
197
+ ### ๐Ÿ’ณ Usage-Based Billing
198
+
199
+ Track usage and generate invoices:
200
+
201
+ ```python
202
+ from svc_infra.billing import BillingService
203
+
204
+ billing = BillingService(session=db, tenant_id="tenant_123")
205
+
206
+ # Record API usage (idempotent)
207
+ billing.record_usage(metric="api_calls", amount=1, idempotency_key="req_abc")
208
+
209
+ # Generate monthly invoice
210
+ invoice = billing.generate_monthly_invoice(
211
+ period_start=datetime(2025, 1, 1),
212
+ period_end=datetime(2025, 2, 1),
213
+ )
214
+ ```
215
+
216
+ **Includes:** Usage events, aggregation, plans & entitlements, subscriptions, invoices, Stripe sync hooks.
217
+
218
+ ### โšก Background Jobs
219
+
220
+ Redis-backed job queue with retries:
221
+
222
+ ```python
223
+ from svc_infra.jobs.easy import easy_jobs
224
+
225
+ queue, scheduler = easy_jobs() # Auto-detects Redis or uses memory
226
+
227
+ # Enqueue work
228
+ queue.enqueue("send_email", {"to": "user@example.com", "template": "welcome"})
229
+
230
+ # Schedule recurring tasks
231
+ scheduler.add("cleanup", interval_seconds=3600, target="myapp.tasks:cleanup")
232
+ ```
233
+
234
+ ```bash
235
+ # Run the worker
236
+ svc-infra jobs run
237
+ ```
238
+
239
+ **Includes:** Visibility timeout, exponential backoff, dead letter queue, interval scheduler, CLI worker.
240
+
241
+ ### ๐Ÿ”— Webhooks
242
+
243
+ Send and receive webhooks with proper security:
244
+
245
+ ```python
246
+ from svc_infra.webhooks import add_webhooks, WebhookService
247
+
248
+ add_webhooks(app) # Adds subscription management routes
249
+
250
+ # Publish events
251
+ webhook_service.publish("invoice.paid", {"invoice_id": "inv_123"})
252
+
253
+ # Verify incoming webhooks
254
+ @app.post("/webhooks/external")
255
+ async def receive(payload=Depends(require_signature(lambda: ["secret1", "secret2"]))):
256
+ return {"ok": True}
257
+ ```
258
+
259
+ **Includes:** Subscription store, HMAC-SHA256 signing, delivery retries, idempotent processing.
260
+
261
+ ### ๐Ÿ“Š Observability
262
+
263
+ Production monitoring out of the box:
264
+
265
+ ```python
266
+ app = easy_service_app(name="MyAPI", release="1.0.0")
267
+ # Prometheus metrics at /metrics
268
+ # Health checks at /healthz, /readyz, /startupz
269
+ # Request tracing with OpenTelemetry
270
+ ```
271
+
272
+ ```bash
273
+ # Generate Grafana dashboards
274
+ svc-infra obs dashboard --service myapi --output ./dashboards/
275
+ ```
276
+
277
+ **Includes:** Prometheus metrics, Grafana dashboard generator, OTEL integration, SLO helpers.
278
+
279
+ ## โš™๏ธ Configuration
280
+
281
+ Everything is configurable via environment variables:
282
+
283
+ ```bash
284
+ # Database
285
+ SQL_URL=postgresql://user:pass@localhost/mydb
286
+ MONGO_URL=mongodb://localhost:27017
287
+
288
+ # Auth
289
+ AUTH_JWT__SECRET=your-secret-key
290
+ AUTH_SMTP_HOST=smtp.sendgrid.net
291
+
292
+ # Jobs
293
+ JOBS_DRIVER=redis
294
+ REDIS_URL=redis://localhost:6379
295
+
296
+ # Storage
297
+ STORAGE_BACKEND=s3
298
+ STORAGE_S3_BUCKET=my-uploads
299
+
300
+ # Observability
301
+ ENABLE_OBS=true
302
+ METRICS_PATH=/metrics
303
+ ```
304
+
305
+ See the [Environment Reference](docs/environment.md) for all options.
306
+
307
+ ## ๐Ÿ“– Documentation
308
+
309
+ | Module | Description | Guide |
310
+ |--------|-------------|-------|
311
+ | **API** | FastAPI bootstrap, middleware, versioning | [docs/api.md](docs/api.md) |
312
+ | **Auth** | Sessions, OAuth/OIDC, MFA, API keys | [docs/auth.md](docs/auth.md) |
313
+ | **Billing** | Usage tracking, subscriptions, invoices | [docs/billing.md](docs/billing.md) |
314
+ | **Database** | SQL + MongoDB, migrations, patterns | [docs/database.md](docs/database.md) |
315
+ | **Jobs** | Background tasks, scheduling | [docs/jobs.md](docs/jobs.md) |
316
+ | **Webhooks** | Publishing, signing, verification | [docs/webhooks.md](docs/webhooks.md) |
317
+ | **Cache** | Redis/memory caching, TTL helpers | [docs/cache.md](docs/cache.md) |
318
+ | **Storage** | S3, local, memory file storage | [docs/storage.md](docs/storage.md) |
319
+ | **Observability** | Metrics, tracing, dashboards | [docs/observability.md](docs/observability.md) |
320
+ | **Security** | Password policy, headers, MFA | [docs/security.md](docs/security.md) |
321
+ | **Tenancy** | Multi-tenant isolation | [docs/tenancy.md](docs/tenancy.md) |
322
+ | **CLI** | Command-line tools | [docs/cli.md](docs/cli.md) |
323
+
324
+ ## ๐Ÿƒ Running the Example
325
+
326
+ See all features working together:
327
+
328
+ ```bash
329
+ git clone https://github.com/nfraxlab/svc-infra.git
330
+ cd svc-infra
331
+
332
+ # Setup and run
333
+ make setup-template # Creates DB, runs migrations
334
+ make run-template # Starts at http://localhost:8001
335
+ ```
336
+
337
+ Visit http://localhost:8001/docs to explore the API.
338
+
339
+ ## ๐Ÿค Related Packages
340
+
341
+ svc-infra is part of the **nfrax** infrastructure suite:
342
+
343
+ | Package | Purpose |
344
+ |---------|---------|
345
+ | **[svc-infra](https://github.com/nfraxlab/svc-infra)** | Backend infrastructure (auth, billing, jobs, webhooks) |
346
+ | **[ai-infra](https://github.com/nfraxlab/ai-infra)** | AI/LLM infrastructure (agents, tools, RAG, MCP) |
347
+ | **[fin-infra](https://github.com/nfraxlab/fin-infra)** | Financial infrastructure (banking, portfolio, insights) |
348
+
349
+ ## ๐Ÿ“„ License
350
+
351
+ MIT License - use it for anything.
352
+
353
+ ---
354
+
355
+ <div align="center">
356
+
357
+ **Built with โค๏ธ by [nfraxlab](https://github.com/nfraxlab)**
358
+
359
+ [โญ Star us on GitHub](https://github.com/nfraxlab/svc-infra) ยท [๐Ÿ“ฆ View on PyPI](https://pypi.org/project/svc-infra/)
360
+
361
+ </div>
362
+