ohmyapi 0.1.24__tar.gz → 0.1.25__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 (27) hide show
  1. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/PKG-INFO +23 -8
  2. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/README.md +22 -7
  3. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/pyproject.toml +1 -1
  4. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/core/runtime.py +7 -4
  5. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/core/templates/app/routes.py.j2 +6 -3
  6. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/core/templates/project/settings.py.j2 +1 -1
  7. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/__init__.py +0 -0
  8. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/__main__.py +0 -0
  9. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/builtin/auth/__init__.py +0 -0
  10. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/builtin/auth/models.py +0 -0
  11. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/builtin/auth/permissions.py +0 -0
  12. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/builtin/auth/routes.py +0 -0
  13. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/builtin/demo/__init__.py +0 -0
  14. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/builtin/demo/models.py +0 -0
  15. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/builtin/demo/routes.py +0 -0
  16. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/cli.py +0 -0
  17. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/core/__init__.py +0 -0
  18. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/core/scaffolding.py +0 -0
  19. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/core/templates/app/__init__.py.j2 +0 -0
  20. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/core/templates/app/models.py.j2 +0 -0
  21. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/core/templates/project/README.md.j2 +0 -0
  22. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/core/templates/project/pyproject.toml.j2 +0 -0
  23. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/db/__init__.py +0 -0
  24. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/db/exceptions.py +0 -0
  25. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/db/model/__init__.py +0 -0
  26. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/db/model/model.py +0 -0
  27. {ohmyapi-0.1.24 → ohmyapi-0.1.25}/src/ohmyapi/router.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ohmyapi
3
- Version: 0.1.24
3
+ Version: 0.1.25
4
4
  Summary: A Django-like but async web-framework based on FastAPI and TortoiseORM.
5
5
  License-Expression: MIT
6
6
  Keywords: fastapi,tortoise,orm,async,web-framework
@@ -62,7 +62,7 @@ It is ***blazingly fast***, extremely ***fun to use*** and comes with ***batteri
62
62
  **Creating a Project**
63
63
 
64
64
  ```
65
- pip install ohmyapi
65
+ pipx install ohmyapi
66
66
  ohmyapi startproject myproject
67
67
  cd myproject
68
68
  ```
@@ -159,24 +159,29 @@ from ohmyapi.db.exceptions import DoesNotExist
159
159
 
160
160
  from .models import Tournament
161
161
 
162
- # Expose your app's routes via `router = fastapi.APIRouter`.
163
- # Use prefixes wisely to avoid cross-app namespace-collisions.
162
+ # OhMyAPI will automatically pick up all instances of `fastapi.APIRouter` and
163
+ # add their routes to the main project router.
164
+ #
165
+ # Note:
166
+ # Use prefixes wisely to avoid cross-app namespace-collisions!
164
167
  # Tags improve the UX of the OpenAPI docs at /docs.
165
- router = APIRouter(prefix="/tournament", tags=['Tournament'])
168
+ #
169
+ tournament_router = APIRouter(prefix="/tournament", tags=['Tournament'])
166
170
 
167
- @router.get("/")
171
+
172
+ @tournament_router.get("/")
168
173
  async def list():
169
174
  queryset = Tournament.all()
170
175
  return await Tournament.Schema.model.from_queryset(queryset)
171
176
 
172
177
 
173
- @router.post("/", status_code=HTTPStatus.CREATED)
178
+ @tournament_router.post("/", status_code=HTTPStatus.CREATED)
174
179
  async def post(tournament: Tournament.Schema.readonly):
175
180
  queryset = Tournament.create(**payload.model_dump())
176
181
  return await Tournament.Schema.model.from_queryset(queryset)
177
182
 
178
183
 
179
- @router.get("/:id")
184
+ @tournament_router.get("/:id")
180
185
  async def get(id: str):
181
186
  try:
182
187
  queryset = Tournament.get(id=id)
@@ -184,6 +189,16 @@ async def get(id: str):
184
189
  except DoesNotExist:
185
190
  raise HTTPException(status_code=404, detail="not found")
186
191
 
192
+
193
+ @tournament_router.delete("/:id")
194
+ async def delete(id: str):
195
+ try:
196
+ tournament = await Tournament.get(id=id)
197
+ return await Tournament.Schema.model.from_queryset(tournament.delete())
198
+ except DoesNotExist:
199
+ raise HTTPException(status_code=404, detail="not found")
200
+
201
+
187
202
  ...
188
203
  ```
189
204
 
@@ -30,7 +30,7 @@ It is ***blazingly fast***, extremely ***fun to use*** and comes with ***batteri
30
30
  **Creating a Project**
31
31
 
32
32
  ```
33
- pip install ohmyapi
33
+ pipx install ohmyapi
34
34
  ohmyapi startproject myproject
35
35
  cd myproject
36
36
  ```
@@ -127,24 +127,29 @@ from ohmyapi.db.exceptions import DoesNotExist
127
127
 
128
128
  from .models import Tournament
129
129
 
130
- # Expose your app's routes via `router = fastapi.APIRouter`.
131
- # Use prefixes wisely to avoid cross-app namespace-collisions.
130
+ # OhMyAPI will automatically pick up all instances of `fastapi.APIRouter` and
131
+ # add their routes to the main project router.
132
+ #
133
+ # Note:
134
+ # Use prefixes wisely to avoid cross-app namespace-collisions!
132
135
  # Tags improve the UX of the OpenAPI docs at /docs.
133
- router = APIRouter(prefix="/tournament", tags=['Tournament'])
136
+ #
137
+ tournament_router = APIRouter(prefix="/tournament", tags=['Tournament'])
134
138
 
135
- @router.get("/")
139
+
140
+ @tournament_router.get("/")
136
141
  async def list():
137
142
  queryset = Tournament.all()
138
143
  return await Tournament.Schema.model.from_queryset(queryset)
139
144
 
140
145
 
141
- @router.post("/", status_code=HTTPStatus.CREATED)
146
+ @tournament_router.post("/", status_code=HTTPStatus.CREATED)
142
147
  async def post(tournament: Tournament.Schema.readonly):
143
148
  queryset = Tournament.create(**payload.model_dump())
144
149
  return await Tournament.Schema.model.from_queryset(queryset)
145
150
 
146
151
 
147
- @router.get("/:id")
152
+ @tournament_router.get("/:id")
148
153
  async def get(id: str):
149
154
  try:
150
155
  queryset = Tournament.get(id=id)
@@ -152,6 +157,16 @@ async def get(id: str):
152
157
  except DoesNotExist:
153
158
  raise HTTPException(status_code=404, detail="not found")
154
159
 
160
+
161
+ @tournament_router.delete("/:id")
162
+ async def delete(id: str):
163
+ try:
164
+ tournament = await Tournament.get(id=id)
165
+ return await Tournament.Schema.model.from_queryset(tournament.delete())
166
+ except DoesNotExist:
167
+ raise HTTPException(status_code=404, detail="not found")
168
+
169
+
155
170
  ...
156
171
  ```
157
172
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ohmyapi"
3
- version = "0.1.24"
3
+ version = "0.1.25"
4
4
  description = "A Django-like but async web-framework based on FastAPI and TortoiseORM."
5
5
  license = "MIT"
6
6
  keywords = ["fastapi", "tortoise", "orm", "async", "web-framework"]
@@ -211,7 +211,7 @@ class App:
211
211
  self.model_modules: List[str] = []
212
212
 
213
213
  # The APIRouter
214
- self.router: Optional[APIRouter] = None
214
+ self.router: APIRouter = APIRouter()
215
215
 
216
216
  # Import the app, so its __init__.py runs.
217
217
  importlib.import_module(self.name)
@@ -226,9 +226,12 @@ class App:
226
226
  # Locate the APIRouter
227
227
  try:
228
228
  routes_mod = importlib.import_module(f"{self.name}.routes")
229
- router = getattr(routes_mod, "router", None)
230
- if isinstance(router, APIRouter):
231
- self.router = router
229
+ for attr_name in dir(routes_mod):
230
+ if attr_name.startswith("__"):
231
+ continue
232
+ attr = getattr(routes_mod, attr_name)
233
+ if isinstance(attr, APIRouter):
234
+ self.router.include_router(attr)
232
235
  except ModuleNotFoundError:
233
236
  pass
234
237
 
@@ -4,13 +4,16 @@ from . import models
4
4
 
5
5
  from typing import List
6
6
 
7
- # Expose your app's routes via `router = fastapi.APIRouter`.
8
- # Use prefixes wisely to avoid cross-app namespace-collisions.
7
+ # OhMyAPI will automatically pick up all instances of `fastapi.APIRouter` and
8
+ # add their routes to the main project router.
9
+ #
10
+ # Note:
11
+ # Use prefixes wisely to avoid cross-app namespace-collisions!
9
12
  # Tags improve the UX of the OpenAPI docs at /docs.
13
+ #
10
14
  router = APIRouter(prefix="/{{ app_name }}", tags=['{{ app_name }}'])
11
15
 
12
16
 
13
-
14
17
  @router.get("/")
15
18
  async def list():
16
19
  """List all ..."""
@@ -2,6 +2,6 @@
2
2
  PROJECT_NAME = "MyProject"
3
3
  DATABASE_URL = "sqlite://db.sqlite3"
4
4
  INSTALLED_APPS = [
5
- #'ohmyapi_auth',
5
+ #"ohmyapi_auth",
6
6
  ]
7
7
 
File without changes
File without changes