FastAPI-fastkit 1.0.0__py3-none-any.whl → 1.0.2__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 (128) hide show
  1. fastapi_fastkit/__init__.py +10 -1
  2. fastapi_fastkit/backend/main.py +482 -482
  3. fastapi_fastkit/backend/transducer.py +106 -106
  4. fastapi_fastkit/cli.py +664 -631
  5. fastapi_fastkit/core/settings.py +155 -155
  6. fastapi_fastkit/fastapi_project_template/README.md +90 -90
  7. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/.env-tpl +1 -1
  8. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/.gitignore-tpl +30 -30
  9. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/README.md-tpl +107 -107
  10. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/requirements.txt-tpl +36 -36
  11. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/format.sh-tpl +5 -5
  12. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/lint.sh-tpl +5 -5
  13. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/run-server.sh-tpl +8 -8
  14. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/test.sh-tpl +6 -6
  15. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/setup.cfg-tpl +14 -14
  16. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/setup.py-tpl +25 -25
  17. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/api/api.py-tpl +9 -9
  18. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/api/routes/items.py-tpl +57 -57
  19. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/core/config.py-tpl +64 -64
  20. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/crud/items.py-tpl +21 -21
  21. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/main.py-tpl +26 -26
  22. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/mocks/mock_items.json-tpl +8 -8
  23. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/schemas/items.py-tpl +22 -22
  24. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/tests/conftest.py-tpl +42 -42
  25. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/tests/test_items.py-tpl +48 -48
  26. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/.env-tpl +1 -1
  27. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/.gitignore-tpl +191 -191
  28. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/README.md-tpl +156 -156
  29. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/requirements.txt-tpl +36 -36
  30. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/format.sh-tpl +5 -5
  31. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/lint.sh-tpl +5 -5
  32. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/run-server.sh-tpl +8 -8
  33. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/test.sh-tpl +6 -6
  34. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/setup.cfg-tpl +12 -12
  35. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/setup.py-tpl +27 -27
  36. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/.DS_Store +0 -0
  37. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/api/api.py-tpl +9 -9
  38. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/api/routes/items.py-tpl +172 -172
  39. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/core/config.py-tpl +64 -64
  40. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/crud/items.py-tpl +21 -21
  41. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/helper/exceptions.py-tpl +103 -103
  42. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/helper/pagination.py-tpl +72 -72
  43. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/main.py-tpl +39 -39
  44. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/mocks/mock_items.json-tpl +8 -8
  45. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/schemas/base.py-tpl +49 -49
  46. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/schemas/items.py-tpl +22 -22
  47. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/utils/documents.py-tpl +20 -20
  48. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/tests/conftest.py-tpl +42 -42
  49. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/tests/test_items.py-tpl +61 -61
  50. fastapi_fastkit/fastapi_project_template/fastapi-default/README.md-tpl +101 -101
  51. fastapi_fastkit/fastapi_project_template/fastapi-default/scripts/run-server.sh-tpl +8 -8
  52. fastapi_fastkit/fastapi_project_template/fastapi-default/setup.py-tpl +22 -22
  53. fastapi_fastkit/fastapi_project_template/fastapi-default/src/mocks/mock_items.json-tpl +8 -8
  54. fastapi_fastkit/fastapi_project_template/fastapi-default/tests/conftest.py-tpl +30 -30
  55. fastapi_fastkit/fastapi_project_template/fastapi-default/tests/test_items.py-tpl +44 -44
  56. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/.env-tpl +1 -1
  57. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/.gitignore-tpl +30 -30
  58. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/Dockerfile-tpl +23 -23
  59. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/README.md-tpl +119 -119
  60. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/requirements.txt-tpl +36 -36
  61. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/format.sh-tpl +5 -5
  62. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/lint.sh-tpl +5 -5
  63. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/run-server.sh-tpl +8 -8
  64. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/test.sh-tpl +6 -6
  65. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/setup.cfg-tpl +13 -13
  66. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/setup.py-tpl +22 -22
  67. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/api/api.py-tpl +6 -6
  68. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/api/routes/items.py-tpl +54 -54
  69. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/core/config.py-tpl +64 -64
  70. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/crud/items.py-tpl +15 -15
  71. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/main.py-tpl +26 -26
  72. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/mocks/mock_items.json-tpl +8 -8
  73. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/schemas/items.py-tpl +19 -19
  74. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/tests/conftest.py-tpl +30 -30
  75. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/tests/test_items.py-tpl +44 -44
  76. fastapi_fastkit/fastapi_project_template/fastapi-empty/.env-tpl +1 -1
  77. fastapi_fastkit/fastapi_project_template/fastapi-empty/setup.py-tpl +22 -22
  78. fastapi_fastkit/fastapi_project_template/fastapi-empty/src/core/config.py-tpl +75 -75
  79. fastapi_fastkit/fastapi_project_template/fastapi-empty/src/main.py-tpl +36 -36
  80. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/.env-tpl +9 -9
  81. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/.gitignore-tpl +30 -30
  82. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/Dockerfile-tpl +23 -23
  83. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/README.md-tpl +144 -144
  84. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/alembic.ini-tpl +119 -119
  85. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/docker-compose.yml-tpl +44 -44
  86. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/requirements.txt-tpl +41 -41
  87. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/format.sh-tpl +5 -5
  88. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/lint.sh-tpl +5 -5
  89. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/pre-start.sh-tpl +16 -16
  90. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/run-server.sh-tpl +8 -8
  91. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/test.sh-tpl +10 -10
  92. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/setup.cfg-tpl +13 -13
  93. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/setup.py-tpl +25 -25
  94. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/README-tpl +1 -1
  95. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/env.py-tpl +85 -85
  96. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/script.py.mako-tpl +26 -26
  97. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/versions/bedcdc35b64a_first_alembic.py-tpl +37 -37
  98. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/api/api.py-tpl +11 -11
  99. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/api/deps.py-tpl +19 -19
  100. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/api/routes/items.py-tpl +109 -109
  101. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/core/config.py-tpl +88 -88
  102. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/core/db.py-tpl +53 -53
  103. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/crud/items.py-tpl +102 -102
  104. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/main.py-tpl +45 -45
  105. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/schemas/items.py-tpl +54 -54
  106. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/utils/backend_pre_start.py-tpl +39 -39
  107. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/utils/init_data.py-tpl +23 -23
  108. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/utils/tests_pre_start.py-tpl +39 -39
  109. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/tests/conftest.py-tpl +63 -63
  110. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/tests/test_items.py-tpl +44 -44
  111. fastapi_fastkit/fastapi_project_template/modules/api/routes/new_route.py-tpl +64 -64
  112. fastapi_fastkit/fastapi_project_template/modules/crud/new_route.py-tpl +29 -29
  113. fastapi_fastkit/fastapi_project_template/modules/schemas/new_route.py-tpl +23 -23
  114. fastapi_fastkit/logs/fastkit_debug_20250702_161423.log +21 -0
  115. fastapi_fastkit/logs/fastkit_debug_20250702_162706.log +20 -0
  116. fastapi_fastkit/logs/fastkit_debug_20250702_163010.log +21 -0
  117. fastapi_fastkit/logs/fastkit_debug_20250702_163526.log +21 -0
  118. fastapi_fastkit/logs/fastkit_debug_20250702_164053.log +21 -0
  119. fastapi_fastkit/logs/fastkit_debug_20250702_165220.log +21 -0
  120. fastapi_fastkit/logs/fastkit_debug_20250702_165647.log +21 -0
  121. fastapi_fastkit/utils/logging.py +112 -1
  122. fastapi_fastkit/utils/main.py +140 -129
  123. fastapi_fastkit-1.0.2.dist-info/METADATA +320 -0
  124. {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/RECORD +127 -119
  125. {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/WHEEL +1 -1
  126. {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/licenses/LICENSE +21 -21
  127. fastapi_fastkit-1.0.0.dist-info/METADATA +0 -208
  128. {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/entry_points.txt +0 -0
@@ -1,22 +1,22 @@
1
- # --------------------------------------------------------------------------
2
- # package setup module
3
- # --------------------------------------------------------------------------
4
- from setuptools import find_packages, setup
5
-
6
- install_requires: list[str] = [
7
- "fastapi",
8
- "uvicorn",
9
- "pydantic",
10
- "pydantic-settings",
11
- "python-dotenv",
12
- ]
13
-
14
- setup(
15
- name="<project_name>",
16
- description="[FastAPI-fastkit templated] <description>",
17
- author="<author>",
18
- author_email=f"<author_email>",
19
- packages=find_packages(where="src"),
20
- requires=["python (>=3.12)"],
21
- install_requires=install_requires,
22
- )
1
+ # --------------------------------------------------------------------------
2
+ # package setup module
3
+ # --------------------------------------------------------------------------
4
+ from setuptools import find_packages, setup
5
+
6
+ install_requires: list[str] = [
7
+ "fastapi",
8
+ "uvicorn",
9
+ "pydantic",
10
+ "pydantic-settings",
11
+ "python-dotenv",
12
+ ]
13
+
14
+ setup(
15
+ name="<project_name>",
16
+ description="[FastAPI-fastkit templated] <description>",
17
+ author="<author>",
18
+ author_email=f"<author_email>",
19
+ packages=find_packages(where="src"),
20
+ requires=["python (>=3.12)"],
21
+ install_requires=install_requires,
22
+ )
@@ -1,6 +1,6 @@
1
- from fastapi import APIRouter
2
-
3
- from src.api.routes import items
4
-
5
- api_router = APIRouter()
6
- api_router.include_router(items.router)
1
+ from fastapi import APIRouter
2
+
3
+ from src.api.routes import items
4
+
5
+ api_router = APIRouter()
6
+ api_router.include_router(items.router)
@@ -1,54 +1,54 @@
1
- from typing import List
2
-
3
- from fastapi import APIRouter, HTTPException
4
-
5
- from src.crud.items import read_items, write_items
6
- from src.schemas.items import ItemCreate, ItemResponse
7
-
8
- router = APIRouter()
9
-
10
-
11
- @router.get("/items", response_model=List[ItemResponse])
12
- async def read_all_items():
13
- return read_items()
14
-
15
-
16
- @router.get("/items/{item_id}", response_model=ItemResponse)
17
- async def read_item(item_id: int):
18
- items = read_items()
19
- item = next((i for i in items if i["id"] == item_id), None)
20
- if not item:
21
- raise HTTPException(status_code=404, detail="Item not found")
22
- return item
23
-
24
-
25
- @router.post("/items", response_model=ItemResponse, status_code=201)
26
- async def create_item(item: ItemCreate):
27
- items = read_items()
28
- new_id = max(i["id"] for i in items) + 1 if items else 1
29
- new_item = {**item.model_dump(), "id": new_id}
30
- items.append(new_item)
31
- write_items(items)
32
- return new_item
33
-
34
-
35
- @router.put("/items/{item_id}", response_model=ItemResponse)
36
- async def update_item(item_id: int, item: ItemCreate):
37
- items = read_items()
38
- index = next((i for i, v in enumerate(items) if v["id"] == item_id), None)
39
- if index is None:
40
- raise HTTPException(status_code=404, detail="Item not found")
41
- updated_item = {**item.model_dump(), "id": item_id}
42
- items[index] = updated_item
43
- write_items(items)
44
- return updated_item
45
-
46
-
47
- @router.delete("/items/{item_id}")
48
- async def delete_item(item_id: int):
49
- items = read_items()
50
- new_items = [i for i in items if i["id"] != item_id]
51
- if len(new_items) == len(items):
52
- raise HTTPException(status_code=404, detail="Item not found")
53
- write_items(new_items)
54
- return {"message": "Item deleted successfully"}
1
+ from typing import List
2
+
3
+ from fastapi import APIRouter, HTTPException
4
+
5
+ from src.crud.items import read_items, write_items
6
+ from src.schemas.items import ItemCreate, ItemResponse
7
+
8
+ router = APIRouter()
9
+
10
+
11
+ @router.get("/items", response_model=List[ItemResponse])
12
+ async def read_all_items():
13
+ return read_items()
14
+
15
+
16
+ @router.get("/items/{item_id}", response_model=ItemResponse)
17
+ async def read_item(item_id: int):
18
+ items = read_items()
19
+ item = next((i for i in items if i["id"] == item_id), None)
20
+ if not item:
21
+ raise HTTPException(status_code=404, detail="Item not found")
22
+ return item
23
+
24
+
25
+ @router.post("/items", response_model=ItemResponse, status_code=201)
26
+ async def create_item(item: ItemCreate):
27
+ items = read_items()
28
+ new_id = max(i["id"] for i in items) + 1 if items else 1
29
+ new_item = {**item.model_dump(), "id": new_id}
30
+ items.append(new_item)
31
+ write_items(items)
32
+ return new_item
33
+
34
+
35
+ @router.put("/items/{item_id}", response_model=ItemResponse)
36
+ async def update_item(item_id: int, item: ItemCreate):
37
+ items = read_items()
38
+ index = next((i for i, v in enumerate(items) if v["id"] == item_id), None)
39
+ if index is None:
40
+ raise HTTPException(status_code=404, detail="Item not found")
41
+ updated_item = {**item.model_dump(), "id": item_id}
42
+ items[index] = updated_item
43
+ write_items(items)
44
+ return updated_item
45
+
46
+
47
+ @router.delete("/items/{item_id}")
48
+ async def delete_item(item_id: int):
49
+ items = read_items()
50
+ new_items = [i for i in items if i["id"] != item_id]
51
+ if len(new_items) == len(items):
52
+ raise HTTPException(status_code=404, detail="Item not found")
53
+ write_items(new_items)
54
+ return {"message": "Item deleted successfully"}
@@ -1,64 +1,64 @@
1
- # --------------------------------------------------------------------------
2
- # Configuration module
3
- # --------------------------------------------------------------------------
4
- import secrets
5
- import warnings
6
- from typing import Annotated, Any, Literal
7
-
8
- from pydantic import AnyUrl, BeforeValidator, computed_field, model_validator
9
- from pydantic_settings import BaseSettings, SettingsConfigDict
10
- from typing_extensions import Self
11
-
12
-
13
- def parse_cors(v: Any) -> list[str] | str:
14
- if isinstance(v, str) and not v.startswith("["):
15
- return [i.strip() for i in v.split(",")]
16
- elif isinstance(v, list | str):
17
- return v
18
- raise ValueError(v)
19
-
20
-
21
- class Settings(BaseSettings):
22
- model_config = SettingsConfigDict(
23
- env_file=".env",
24
- env_ignore_empty=True,
25
- extra="ignore",
26
- )
27
-
28
- SECRET_KEY: str = secrets.token_urlsafe(32)
29
- ENVIRONMENT: Literal["development", "production"] = "development"
30
-
31
- CLIENT_ORIGIN: str = ""
32
-
33
- BACKEND_CORS_ORIGINS: Annotated[list[AnyUrl] | str, BeforeValidator(parse_cors)] = (
34
- []
35
- )
36
-
37
- @computed_field # type: ignore[prop-decorator]
38
- @property
39
- def all_cors_origins(self) -> list[str]:
40
- return [str(origin).rstrip("/") for origin in self.BACKEND_CORS_ORIGINS] + [
41
- self.CLIENT_ORIGIN
42
- ]
43
-
44
- PROJECT_NAME: str = "<project_name>"
45
-
46
- def _check_default_secret(self, var_name: str, value: str | None) -> None:
47
- if value == "changethis":
48
- message = (
49
- f'The value of {var_name} is "changethis", '
50
- "for security, please change it, at least for deployments."
51
- )
52
- if self.ENVIRONMENT == "development":
53
- warnings.warn(message, stacklevel=1)
54
- else:
55
- raise ValueError(message)
56
-
57
- @model_validator(mode="after")
58
- def _enforce_non_default_secrets(self) -> Self:
59
- self._check_default_secret("SECRET_KEY", self.SECRET_KEY)
60
-
61
- return self
62
-
63
-
64
- settings = Settings() # type: ignore
1
+ # --------------------------------------------------------------------------
2
+ # Configuration module
3
+ # --------------------------------------------------------------------------
4
+ import secrets
5
+ import warnings
6
+ from typing import Annotated, Any, Literal
7
+
8
+ from pydantic import AnyUrl, BeforeValidator, computed_field, model_validator
9
+ from pydantic_settings import BaseSettings, SettingsConfigDict
10
+ from typing_extensions import Self
11
+
12
+
13
+ def parse_cors(v: Any) -> list[str] | str:
14
+ if isinstance(v, str) and not v.startswith("["):
15
+ return [i.strip() for i in v.split(",")]
16
+ elif isinstance(v, list | str):
17
+ return v
18
+ raise ValueError(v)
19
+
20
+
21
+ class Settings(BaseSettings):
22
+ model_config = SettingsConfigDict(
23
+ env_file=".env",
24
+ env_ignore_empty=True,
25
+ extra="ignore",
26
+ )
27
+
28
+ SECRET_KEY: str = secrets.token_urlsafe(32)
29
+ ENVIRONMENT: Literal["development", "production"] = "development"
30
+
31
+ CLIENT_ORIGIN: str = ""
32
+
33
+ BACKEND_CORS_ORIGINS: Annotated[list[AnyUrl] | str, BeforeValidator(parse_cors)] = (
34
+ []
35
+ )
36
+
37
+ @computed_field # type: ignore[prop-decorator]
38
+ @property
39
+ def all_cors_origins(self) -> list[str]:
40
+ return [str(origin).rstrip("/") for origin in self.BACKEND_CORS_ORIGINS] + [
41
+ self.CLIENT_ORIGIN
42
+ ]
43
+
44
+ PROJECT_NAME: str = "<project_name>"
45
+
46
+ def _check_default_secret(self, var_name: str, value: str | None) -> None:
47
+ if value == "changethis":
48
+ message = (
49
+ f'The value of {var_name} is "changethis", '
50
+ "for security, please change it, at least for deployments."
51
+ )
52
+ if self.ENVIRONMENT == "development":
53
+ warnings.warn(message, stacklevel=1)
54
+ else:
55
+ raise ValueError(message)
56
+
57
+ @model_validator(mode="after")
58
+ def _enforce_non_default_secrets(self) -> Self:
59
+ self._check_default_secret("SECRET_KEY", self.SECRET_KEY)
60
+
61
+ return self
62
+
63
+
64
+ settings = Settings() # type: ignore
@@ -1,15 +1,15 @@
1
- import json
2
- import os
3
- from typing import List
4
-
5
- MOCK_FILE = os.path.join(os.path.dirname(__file__), "../mocks/mock_items.json")
6
-
7
-
8
- def read_items():
9
- with open(MOCK_FILE, "r") as file:
10
- return json.load(file)
11
-
12
-
13
- def write_items(items: List[dict]):
14
- with open(MOCK_FILE, "w") as file:
15
- json.dump(items, file, indent=2)
1
+ import json
2
+ import os
3
+ from typing import List
4
+
5
+ MOCK_FILE = os.path.join(os.path.dirname(__file__), "../mocks/mock_items.json")
6
+
7
+
8
+ def read_items():
9
+ with open(MOCK_FILE, "r") as file:
10
+ return json.load(file)
11
+
12
+
13
+ def write_items(items: List[dict]):
14
+ with open(MOCK_FILE, "w") as file:
15
+ json.dump(items, file, indent=2)
@@ -1,26 +1,26 @@
1
- # --------------------------------------------------------------------------
2
- # Main server application module
3
- # --------------------------------------------------------------------------
4
- from contextlib import asynccontextmanager
5
-
6
- from fastapi import FastAPI
7
- from starlette.middleware.cors import CORSMiddleware
8
-
9
- from src.api.api import api_router
10
- from src.core.config import settings
11
-
12
- app = FastAPI(
13
- title=settings.PROJECT_NAME,
14
- )
15
-
16
- if settings.all_cors_origins:
17
- app.add_middleware(
18
- CORSMiddleware,
19
- allow_origins=settings.all_cors_origins,
20
- allow_credentials=True,
21
- allow_methods=["*"],
22
- allow_headers=["*"],
23
- )
24
-
25
-
26
- app.include_router(api_router)
1
+ # --------------------------------------------------------------------------
2
+ # Main server application module
3
+ # --------------------------------------------------------------------------
4
+ from contextlib import asynccontextmanager
5
+
6
+ from fastapi import FastAPI
7
+ from starlette.middleware.cors import CORSMiddleware
8
+
9
+ from src.api.api import api_router
10
+ from src.core.config import settings
11
+
12
+ app = FastAPI(
13
+ title=settings.PROJECT_NAME,
14
+ )
15
+
16
+ if settings.all_cors_origins:
17
+ app.add_middleware(
18
+ CORSMiddleware,
19
+ allow_origins=settings.all_cors_origins,
20
+ allow_credentials=True,
21
+ allow_methods=["*"],
22
+ allow_headers=["*"],
23
+ )
24
+
25
+
26
+ app.include_router(api_router)
@@ -1,8 +1,8 @@
1
- [
2
- {
3
- "id": 1,
4
- "name": "Test Item 1",
5
- "price": 20.0,
6
- "category": "test"
7
- }
8
- ]
1
+ [
2
+ {
3
+ "id": 1,
4
+ "name": "Test Item 1",
5
+ "price": 20.0,
6
+ "category": "test"
7
+ }
8
+ ]
@@ -1,19 +1,19 @@
1
- from typing import Optional
2
-
3
- from pydantic import BaseModel, ConfigDict
4
-
5
-
6
- class ItemBase(BaseModel):
7
- name: str
8
- description: Optional[str] = None
9
- price: float
10
- category: str
11
-
12
-
13
- class ItemCreate(ItemBase):
14
- pass
15
-
16
-
17
- class ItemResponse(ItemBase):
18
- id: int
19
- model_config = ConfigDict(from_attributes=True)
1
+ from typing import Optional
2
+
3
+ from pydantic import BaseModel, ConfigDict
4
+
5
+
6
+ class ItemBase(BaseModel):
7
+ name: str
8
+ description: Optional[str] = None
9
+ price: float
10
+ category: str
11
+
12
+
13
+ class ItemCreate(ItemBase):
14
+ pass
15
+
16
+
17
+ class ItemResponse(ItemBase):
18
+ id: int
19
+ model_config = ConfigDict(from_attributes=True)
@@ -1,30 +1,30 @@
1
- # --------------------------------------------------------------------------
2
- # pytest runtime configuration module
3
- # --------------------------------------------------------------------------
4
- from collections.abc import Generator
5
-
6
- import os
7
- import json
8
- import pytest
9
- from fastapi.testclient import TestClient
10
-
11
- from src.main import app
12
-
13
- MOCK_FILE = os.path.join(os.path.dirname(__file__), "../src/mocks/mock_items.json")
14
-
15
-
16
- @pytest.fixture(autouse=True)
17
- def reset_mock_data():
18
- initial_data = [
19
- {"id": 1, "name": "Test Item 1", "price": 10.5, "category": "test"},
20
- {"id": 2, "name": "Test Item 2", "price": 20.0, "category": "test"},
21
- ]
22
- with open(MOCK_FILE, "w") as file:
23
- json.dump(initial_data, file)
24
- yield
25
-
26
-
27
- @pytest.fixture(scope="module")
28
- def client() -> Generator[TestClient, None, None]:
29
- with TestClient(app) as c:
30
- yield c
1
+ # --------------------------------------------------------------------------
2
+ # pytest runtime configuration module
3
+ # --------------------------------------------------------------------------
4
+ from collections.abc import Generator
5
+
6
+ import os
7
+ import json
8
+ import pytest
9
+ from fastapi.testclient import TestClient
10
+
11
+ from src.main import app
12
+
13
+ MOCK_FILE = os.path.join(os.path.dirname(__file__), "../src/mocks/mock_items.json")
14
+
15
+
16
+ @pytest.fixture(autouse=True)
17
+ def reset_mock_data():
18
+ initial_data = [
19
+ {"id": 1, "name": "Test Item 1", "price": 10.5, "category": "test"},
20
+ {"id": 2, "name": "Test Item 2", "price": 20.0, "category": "test"},
21
+ ]
22
+ with open(MOCK_FILE, "w") as file:
23
+ json.dump(initial_data, file)
24
+ yield
25
+
26
+
27
+ @pytest.fixture(scope="module")
28
+ def client() -> Generator[TestClient, None, None]:
29
+ with TestClient(app) as c:
30
+ yield c
@@ -1,44 +1,44 @@
1
- # --------------------------------------------------------------------------
2
- # Item endpoint testcases
3
- # --------------------------------------------------------------------------
4
- import json
5
-
6
- import pytest
7
-
8
-
9
- def test_read_all_items(client):
10
- response = client.get("/items")
11
- assert response.status_code == 200
12
- assert len(response.json()) == 2
13
-
14
-
15
- def test_read_item_success(client):
16
- response = client.get("/items/1")
17
- assert response.status_code == 200
18
- assert response.json()["name"] == "Test Item 1"
19
-
20
-
21
- def test_read_item_not_found(client):
22
- response = client.get("/items/999")
23
- assert response.status_code == 404
24
-
25
-
26
- def test_create_item(client):
27
- new_item = {"name": "New Item", "price": 30.0, "category": "new"}
28
- response = client.post("/items", json=new_item)
29
- assert response.status_code == 201
30
- assert response.json()["id"] == 3
31
-
32
-
33
- def test_update_item(client):
34
- updated_data = {"name": "Updated Item", "price": 15.0, "category": "updated"}
35
- response = client.put("/items/1", json=updated_data)
36
- assert response.status_code == 200
37
- assert response.json()["name"] == "Updated Item"
38
-
39
-
40
- def test_delete_item(client):
41
- response = client.delete("/items/1")
42
- assert response.status_code == 200
43
- response = client.get("/items/1")
44
- assert response.status_code == 404
1
+ # --------------------------------------------------------------------------
2
+ # Item endpoint testcases
3
+ # --------------------------------------------------------------------------
4
+ import json
5
+
6
+ import pytest
7
+
8
+
9
+ def test_read_all_items(client):
10
+ response = client.get("/items")
11
+ assert response.status_code == 200
12
+ assert len(response.json()) == 2
13
+
14
+
15
+ def test_read_item_success(client):
16
+ response = client.get("/items/1")
17
+ assert response.status_code == 200
18
+ assert response.json()["name"] == "Test Item 1"
19
+
20
+
21
+ def test_read_item_not_found(client):
22
+ response = client.get("/items/999")
23
+ assert response.status_code == 404
24
+
25
+
26
+ def test_create_item(client):
27
+ new_item = {"name": "New Item", "price": 30.0, "category": "new"}
28
+ response = client.post("/items", json=new_item)
29
+ assert response.status_code == 201
30
+ assert response.json()["id"] == 3
31
+
32
+
33
+ def test_update_item(client):
34
+ updated_data = {"name": "Updated Item", "price": 15.0, "category": "updated"}
35
+ response = client.put("/items/1", json=updated_data)
36
+ assert response.status_code == 200
37
+ assert response.json()["name"] == "Updated Item"
38
+
39
+
40
+ def test_delete_item(client):
41
+ response = client.delete("/items/1")
42
+ assert response.status_code == 200
43
+ response = client.get("/items/1")
44
+ assert response.status_code == 404
@@ -1 +1 @@
1
- SECRET_KEY=changethis
1
+ SECRET_KEY=changethis
@@ -1,22 +1,22 @@
1
- # --------------------------------------------------------------------------
2
- # package setup module
3
- # --------------------------------------------------------------------------
4
- from setuptools import find_packages, setup
5
-
6
- install_requires: list[str] = [
7
- "fastapi",
8
- "uvicorn",
9
- "pydantic",
10
- "pydantic-settings",
11
- "python-dotenv",
12
- ]
13
-
14
- setup(
15
- name="<project_name>",
16
- description="[FastAPI-fastkit templated] <description>",
17
- author="<author>",
18
- author_email=f"<author_email>",
19
- packages=find_packages(where="src"),
20
- requires=["python (>=3.12)"],
21
- install_requires=install_requires,
22
- )
1
+ # --------------------------------------------------------------------------
2
+ # package setup module
3
+ # --------------------------------------------------------------------------
4
+ from setuptools import find_packages, setup
5
+
6
+ install_requires: list[str] = [
7
+ "fastapi",
8
+ "uvicorn",
9
+ "pydantic",
10
+ "pydantic-settings",
11
+ "python-dotenv",
12
+ ]
13
+
14
+ setup(
15
+ name="<project_name>",
16
+ description="[FastAPI-fastkit templated] <description>",
17
+ author="<author>",
18
+ author_email=f"<author_email>",
19
+ packages=find_packages(where="src"),
20
+ requires=["python (>=3.12)"],
21
+ install_requires=install_requires,
22
+ )