ohmyapi 0.2.4__py3-none-any.whl → 0.2.7__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.
ohmyapi/__init__.py CHANGED
@@ -1 +1 @@
1
- from . import db
1
+ __VERSION__ = "0.2.7"
ohmyapi/cli.py CHANGED
@@ -35,6 +35,7 @@ def serve(root: str = ".", host="127.0.0.1", port=8000):
35
35
  project_path = Path(root)
36
36
  project = runtime.Project(project_path)
37
37
  app_instance = project.app()
38
+ app_instance = project.configure_app(app_instance)
38
39
  uvicorn.run(app_instance, host=host, port=int(port), reload=False)
39
40
 
40
41
 
ohmyapi/core/runtime.py CHANGED
@@ -72,23 +72,35 @@ class Project:
72
72
  def is_app_installed(self, name: str) -> bool:
73
73
  return name in getattr(self.settings, "INSTALLED_APPS", [])
74
74
 
75
- def app(self, generate_schemas: bool = False) -> FastAPI:
75
+ def app(self,
76
+ docs_url: str = "/docs",
77
+ ) -> FastAPI:
76
78
  """
77
- Create a FastAPI app, attach all APIRouters from registered apps,
78
- and register ORM lifecycle event handlers.
79
+ Create and return a FastAPI app.
79
80
  """
80
- app = FastAPI(title=getattr(self.settings, "PROJECT_NAME", "OhMyAPI Project"))
81
+ import ohmyapi
82
+ return FastAPI(
83
+ title=getattr(self.settings, "PROJECT_NAME", "OhMyAPI Project"),
84
+ description=getattr(self.settings, "PROJECT_DESCRIPTION", ""),
85
+ docs_url=getattr(self.settings, "DOCS_URL", "/docs"),
86
+ version=ohmyapi.__VERSION__,
87
+ )
81
88
 
82
- # Attach routers from apps
89
+ def configure_app(self, app: FastAPI) -> FastAPI:
90
+ """
91
+ Attach project routes and event handlers to given FastAPI instance.
92
+ """
93
+ # Attach project routes.
83
94
  for app_name, app_def in self._apps.items():
84
- if app_def.router:
85
- app.include_router(app_def.router)
95
+ for router in app_def.routers:
96
+ app.include_router(router)
86
97
 
87
- # Startup / shutdown events
98
+ # Initialize ORM on startup
88
99
  @app.on_event("startup")
89
100
  async def _startup():
90
- await self.init_orm(generate_schemas=generate_schemas)
101
+ await self.init_orm(generate_schemas=False)
91
102
 
103
+ # Close ORM on shutdown
92
104
  @app.on_event("shutdown")
93
105
  async def _shutdown():
94
106
  await self.close_orm()
@@ -333,16 +345,23 @@ class App:
333
345
  module: out,
334
346
  }
335
347
 
348
+ @property
349
+ def routers(self):
350
+ out = []
351
+ for routes_mod in self._routers:
352
+ for r in self._routers[routes_mod]:
353
+ out.append(r)
354
+ return out
355
+
336
356
  @property
337
357
  def routes(self):
338
358
  """
339
359
  Return an APIRouter with all loaded routes.
340
360
  """
341
- router = APIRouter()
342
- for routes_mod in self._routers:
343
- for r in self._routers[routes_mod]:
344
- router.include_router(r)
345
- return router.routes
361
+ out = []
362
+ for r in self.routers:
363
+ out.extend(r.routes)
364
+ return out
346
365
 
347
366
  def dict(self) -> Dict[str, Any]:
348
367
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ohmyapi
3
- Version: 0.2.4
3
+ Version: 0.2.7
4
4
  Summary: Django-flavored scaffolding and management layer around FastAPI, Pydantic, TortoiseORM and Aerich migrations
5
5
  License-Expression: MIT
6
6
  Keywords: fastapi,tortoise,orm,pydantic,async,web-framework
@@ -1,4 +1,4 @@
1
- ohmyapi/__init__.py,sha256=3y8knoHhOjkUMMi7ADheYxBJywXPvpn5JldxMUeWejw,17
1
+ ohmyapi/__init__.py,sha256=8wo4flTaSvqGlIOWARbqD5xEq_In5CHTiPa4m8_Oujo,22
2
2
  ohmyapi/__main__.py,sha256=wcCrL4PjG51r5wVKqJhcoJPTLfHW0wNbD31DrUN0MWI,28
3
3
  ohmyapi/builtin/auth/__init__.py,sha256=vOVCSJX8BALzs8h5ZW9507bjoscP37bncMjdMmBXcMM,42
4
4
  ohmyapi/builtin/auth/models.py,sha256=8az4TKdC6PUha3_HyslKinDT2-yAN-aBoYUQcjxm7Js,1728
@@ -7,9 +7,9 @@ ohmyapi/builtin/auth/routes.py,sha256=r887BWea20vinX88QBuxGzQc9BrIi-LqyStM0V1cl1
7
7
  ohmyapi/builtin/demo/__init__.py,sha256=44Yo3mYmlKSKEwVp6O9urr-C_3qDQzCYLMn6B9i6wew,29
8
8
  ohmyapi/builtin/demo/models.py,sha256=r06rfuhPJaI2fYsQ24L1JCOd67f2GQNfGnkgKAptOX8,1404
9
9
  ohmyapi/builtin/demo/routes.py,sha256=1VTlEttrez6Qnhrz_9sTA-emtfXem0s0BkPVcLvg3k0,1801
10
- ohmyapi/cli.py,sha256=dJVNgpW5S4rCc619AEEKBKuEIAmQs153Ls0ZVaea48w,4173
10
+ ohmyapi/cli.py,sha256=3qOXEns3FNCfD67dy_70PMfdU7kOLIagV8taNSeLL24,4228
11
11
  ohmyapi/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- ohmyapi/core/runtime.py,sha256=90nZQwMxrOn0n7b2XI393ERX3Jem2bd4EJrUdUZLh8U,11849
12
+ ohmyapi/core/runtime.py,sha256=pNfFRk7sFX8FePX6cnb4H7kLh5CauNnA_gmc0rsWIh8,12287
13
13
  ohmyapi/core/scaffolding.py,sha256=SA0SYFd7VcqkOn9xuXgj-yOoVqCZMJo68GGFbm34GE4,2663
14
14
  ohmyapi/core/templates/app/__init__.py.j2,sha256=QwVIQVUGZVhdH1d4NrvL7NTsK4-T4cihzYs8UVX2dt4,43
15
15
  ohmyapi/core/templates/app/models.py.j2,sha256=_3w-vFJ5fgsmncsCv34k_wyCMF78jufbSSglns4gbb0,119
@@ -22,7 +22,7 @@ ohmyapi/db/exceptions.py,sha256=vb4IIUoeYAY6sK42zRtjMy-39IFVi_Qb6mWySTY0jYw,34
22
22
  ohmyapi/db/model/__init__.py,sha256=k3StTNuKatpwZo_Z5JBFa-927eJrzibFE8U4SA82asc,32
23
23
  ohmyapi/db/model/model.py,sha256=ui4g78c5xoS06Dj8Cdk7QgTjRnE68zKeL-AdmeYYPuQ,2776
24
24
  ohmyapi/router.py,sha256=5g0U59glu4hxxnIoTSFzb2S2offkOT3eE39aprzVxwo,83
25
- ohmyapi-0.2.4.dist-info/METADATA,sha256=Qzo5YjAgaujzOPj-K_ZAgntfq3OLpfxTp9z19zmfdWU,2575
26
- ohmyapi-0.2.4.dist-info/WHEEL,sha256=M5asmiAlL6HEcOq52Yi5mmk9KmTVjY2RDPtO4p9DMrc,88
27
- ohmyapi-0.2.4.dist-info/entry_points.txt,sha256=wb3lw8-meAlpiv1mqcQ3m25ukL7djagU_w89GkrC37k,43
28
- ohmyapi-0.2.4.dist-info/RECORD,,
25
+ ohmyapi-0.2.7.dist-info/METADATA,sha256=intrTUslU5Kr_osXBIzNLLaY23s-JAS7nYzO07KuMcI,2575
26
+ ohmyapi-0.2.7.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
27
+ ohmyapi-0.2.7.dist-info/entry_points.txt,sha256=wb3lw8-meAlpiv1mqcQ3m25ukL7djagU_w89GkrC37k,43
28
+ ohmyapi-0.2.7.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.2.0
2
+ Generator: poetry-core 2.2.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any