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,75 +1,75 @@
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
- """Default project configuraion module
23
-
24
- This base module configures your project SECRET_KEY, CORS origins and project name
25
-
26
- **Add your project configurations below**
27
-
28
-
29
- For more information, please refer to the following link:
30
-
31
- https://fastapi.tiangolo.com/advanced/settings/?h=config
32
- """
33
- model_config = SettingsConfigDict(
34
- env_file=".env",
35
- env_ignore_empty=True,
36
- extra="ignore",
37
- )
38
-
39
- SECRET_KEY: str = secrets.token_urlsafe(32)
40
- ENVIRONMENT: Literal["development", "production"] = "development"
41
-
42
- CLIENT_ORIGIN: str = ""
43
-
44
- BACKEND_CORS_ORIGINS: Annotated[list[AnyUrl] | str, BeforeValidator(parse_cors)] = (
45
- []
46
- )
47
-
48
- @computed_field # type: ignore[prop-decorator]
49
- @property
50
- def all_cors_origins(self) -> list[str]:
51
- return [str(origin).rstrip("/") for origin in self.BACKEND_CORS_ORIGINS] + [
52
- self.CLIENT_ORIGIN
53
- ]
54
-
55
- PROJECT_NAME: str = "<project_name>"
56
-
57
- def _check_default_secret(self, var_name: str, value: str | None) -> None:
58
- if value == "changethis":
59
- message = (
60
- f'The value of {var_name} is "changethis", '
61
- "for security, please change it, at least for deployments."
62
- )
63
- if self.ENVIRONMENT == "development":
64
- warnings.warn(message, stacklevel=1)
65
- else:
66
- raise ValueError(message)
67
-
68
- @model_validator(mode="after")
69
- def _enforce_non_default_secrets(self) -> Self:
70
- self._check_default_secret("SECRET_KEY", self.SECRET_KEY)
71
-
72
- return self
73
-
74
-
75
- 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
+ """Default project configuraion module
23
+
24
+ This base module configures your project SECRET_KEY, CORS origins and project name
25
+
26
+ **Add your project configurations below**
27
+
28
+
29
+ For more information, please refer to the following link:
30
+
31
+ https://fastapi.tiangolo.com/advanced/settings/?h=config
32
+ """
33
+ model_config = SettingsConfigDict(
34
+ env_file=".env",
35
+ env_ignore_empty=True,
36
+ extra="ignore",
37
+ )
38
+
39
+ SECRET_KEY: str = secrets.token_urlsafe(32)
40
+ ENVIRONMENT: Literal["development", "production"] = "development"
41
+
42
+ CLIENT_ORIGIN: str = ""
43
+
44
+ BACKEND_CORS_ORIGINS: Annotated[list[AnyUrl] | str, BeforeValidator(parse_cors)] = (
45
+ []
46
+ )
47
+
48
+ @computed_field # type: ignore[prop-decorator]
49
+ @property
50
+ def all_cors_origins(self) -> list[str]:
51
+ return [str(origin).rstrip("/") for origin in self.BACKEND_CORS_ORIGINS] + [
52
+ self.CLIENT_ORIGIN
53
+ ]
54
+
55
+ PROJECT_NAME: str = "<project_name>"
56
+
57
+ def _check_default_secret(self, var_name: str, value: str | None) -> None:
58
+ if value == "changethis":
59
+ message = (
60
+ f'The value of {var_name} is "changethis", '
61
+ "for security, please change it, at least for deployments."
62
+ )
63
+ if self.ENVIRONMENT == "development":
64
+ warnings.warn(message, stacklevel=1)
65
+ else:
66
+ raise ValueError(message)
67
+
68
+ @model_validator(mode="after")
69
+ def _enforce_non_default_secrets(self) -> Self:
70
+ self._check_default_secret("SECRET_KEY", self.SECRET_KEY)
71
+
72
+ return self
73
+
74
+
75
+ settings = Settings() # type: ignore
@@ -1,36 +1,36 @@
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.core.config import settings
10
-
11
- app = FastAPI(
12
- title=settings.PROJECT_NAME,
13
- )
14
-
15
- if settings.all_cors_origins:
16
- app.add_middleware(
17
- CORSMiddleware,
18
- allow_origins=settings.all_cors_origins,
19
- allow_credentials=True,
20
- allow_methods=["*"],
21
- allow_headers=["*"],
22
- )
23
-
24
-
25
- """Add your FastAPI application main routine here
26
-
27
- You can attach customized middlewares, api routes, etc.
28
-
29
-
30
- For more information, please refer to the following link:
31
-
32
- https://fastapi.tiangolo.com/tutorial/
33
- https://fastapi.tiangolo.com/reference/apirouter/?h=apiroute
34
- https://fastapi.tiangolo.com/tutorial/middleware/?h=middle
35
- https://fastapi.tiangolo.com/tutorial/cors/
36
- """
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.core.config import settings
10
+
11
+ app = FastAPI(
12
+ title=settings.PROJECT_NAME,
13
+ )
14
+
15
+ if settings.all_cors_origins:
16
+ app.add_middleware(
17
+ CORSMiddleware,
18
+ allow_origins=settings.all_cors_origins,
19
+ allow_credentials=True,
20
+ allow_methods=["*"],
21
+ allow_headers=["*"],
22
+ )
23
+
24
+
25
+ """Add your FastAPI application main routine here
26
+
27
+ You can attach customized middlewares, api routes, etc.
28
+
29
+
30
+ For more information, please refer to the following link:
31
+
32
+ https://fastapi.tiangolo.com/tutorial/
33
+ https://fastapi.tiangolo.com/reference/apirouter/?h=apiroute
34
+ https://fastapi.tiangolo.com/tutorial/middleware/?h=middle
35
+ https://fastapi.tiangolo.com/tutorial/cors/
36
+ """
@@ -1,9 +1,9 @@
1
- # Backend
2
- SECRET_KEY=changethis
3
-
4
- # Postgres
5
- POSTGRES_SERVER=db
6
- POSTGRES_PORT=5432
7
- POSTGRES_USER=postgres
8
- POSTGRES_PASSWORD=postgres
9
- POSTGRES_DB=item_db
1
+ # Backend
2
+ SECRET_KEY=changethis
3
+
4
+ # Postgres
5
+ POSTGRES_SERVER=db
6
+ POSTGRES_PORT=5432
7
+ POSTGRES_USER=postgres
8
+ POSTGRES_PASSWORD=postgres
9
+ POSTGRES_DB=item_db
@@ -1,30 +1,30 @@
1
- .idea
2
- .ipynb_checkpoints
3
- .mypy_cache
4
- .vscode
5
- __pycache__
6
- .pytest_cache
7
- htmlcov
8
- dist
9
- site
10
- .coverage*
11
- coverage.xml
12
- .netlify
13
- test.db
14
- log.txt
15
- Pipfile.lock
16
- env3.*
17
- env
18
- docs_build
19
- site_build
20
- venv
21
- docs.zip
22
- archive.zip
23
-
24
- # vim temporary files
25
- *~
26
- .*.sw?
27
- .cache
28
-
29
- # macOS
30
- .DS_Store
1
+ .idea
2
+ .ipynb_checkpoints
3
+ .mypy_cache
4
+ .vscode
5
+ __pycache__
6
+ .pytest_cache
7
+ htmlcov
8
+ dist
9
+ site
10
+ .coverage*
11
+ coverage.xml
12
+ .netlify
13
+ test.db
14
+ log.txt
15
+ Pipfile.lock
16
+ env3.*
17
+ env
18
+ docs_build
19
+ site_build
20
+ venv
21
+ docs.zip
22
+ archive.zip
23
+
24
+ # vim temporary files
25
+ *~
26
+ .*.sw?
27
+ .cache
28
+
29
+ # macOS
30
+ .DS_Store
@@ -1,23 +1,23 @@
1
- FROM python:3.12-slim
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && \
6
- apt-get install -y --no-install-recommends \
7
- build-essential \
8
- && rm -rf /var/lib/apt/lists/*
9
-
10
- COPY requirements.txt .
11
- COPY setup.py .
12
- COPY src/ src/
13
- COPY tests/ tests/
14
- COPY scripts/ scripts/
15
-
16
- RUN pip install --no-cache-dir -r requirements.txt
17
-
18
- ENV PYTHONPATH=/app
19
- ENV ENVIRONMENT=production
20
-
21
- EXPOSE 8000
22
-
23
- CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]
1
+ FROM python:3.12-slim
2
+
3
+ WORKDIR /app
4
+
5
+ RUN apt-get update && \
6
+ apt-get install -y --no-install-recommends \
7
+ build-essential \
8
+ && rm -rf /var/lib/apt/lists/*
9
+
10
+ COPY requirements.txt .
11
+ COPY setup.py .
12
+ COPY src/ src/
13
+ COPY tests/ tests/
14
+ COPY scripts/ scripts/
15
+
16
+ RUN pip install --no-cache-dir -r requirements.txt
17
+
18
+ ENV PYTHONPATH=/app
19
+ ENV ENVIRONMENT=production
20
+
21
+ EXPOSE 8000
22
+
23
+ CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]
@@ -1,144 +1,144 @@
1
- # Dockerized FastAPI Item Management API with PostgreSQL
2
-
3
- This project is a Docker containerized FastAPI-based item management API application with PostgreSQL database integration.
4
-
5
- ## Requirements
6
-
7
- - Docker and Docker Compose
8
-
9
- ## Tech Stack
10
-
11
- - Python 3.12+
12
- - FastAPI + uvicorn
13
- - PostgreSQL
14
- - SQLModel (SQLAlchemy + Pydantic)
15
- - Alembic
16
- - Docker & Docker Compose
17
- - pytest
18
- - mypy + black + isort
19
-
20
- ## Project Structure
21
-
22
- ````
23
- .
24
- ├── Dockerfile
25
- ├── README.md
26
- ├── docker-compose.yml
27
- ├── requirements.txt
28
- ├── setup.py
29
- ├── alembic.ini
30
- ├── scripts
31
- │ ├── pre-start.sh
32
- │ └── test.sh
33
- ├── src
34
- │ ├── api
35
- │ │ ├── api.py
36
- │ │ ├── deps.py
37
- │ │ └── routes
38
- │ │ └── items.py
39
- │ ├── core
40
- │ │ ├── config.py
41
- │ │ └── db.py
42
- │ ├── crud
43
- │ │ └── items.py
44
- │ ├── alembic
45
- │ │ ├── env.py
46
- │ │ └── versions/
47
- │ ├── schemas
48
- │ │ └── items.py
49
- │ ├── utils
50
- │ │ ├── backend_pre_start.py
51
- │ │ ├── init_data.py
52
- │ │ └── tests_pre_start.py
53
- │ └── main.py
54
- └── tests
55
- ├── __init__.py
56
- ├── test_items.py
57
- └── conftest.py
58
- ````
59
-
60
-
61
- ## How to Run
62
-
63
- ### Run with Docker
64
-
65
- ````bash
66
- # Build and run with Docker Compose
67
- $ docker-compose up -d
68
-
69
- # Check container status
70
- $ docker-compose ps
71
- ````
72
-
73
-
74
- Once the containers are running, you can check the API documentation at:
75
-
76
- ````
77
- http://localhost:8000/docs # Swagger format
78
- http://localhost:8000/redoc # ReDoc format
79
- ````
80
-
81
-
82
- ### Run in Development Mode (Inside Container)
83
-
84
- ````bash
85
- # Run the application in development mode (using `--reload` option)
86
- $ docker-compose exec app uvicorn src.main:app --reload --host 0.0.0.0
87
- ````
88
-
89
-
90
- ## API Endpoints
91
-
92
- | Method | Endpoint | Description |
93
- |--------|------------------|----------------------------|
94
- | GET | `/items/` | List all items |
95
- | GET | `/items/{id}` | Get single item |
96
- | POST | `/items/` | Create new item |
97
- | PUT | `/items/{id}` | Update existing item |
98
- | DELETE | `/items/{id}` | Delete item |
99
-
100
- ## Key Features
101
-
102
- - Persistent storage using PostgreSQL database
103
- - Database migrations using Alembic
104
- - ORM using SQLModel (SQLAlchemy + Pydantic)
105
- - Full containerization via Docker Compose
106
- - Automatic loading of initial sample data
107
- - Pydantic model-based data validation
108
- - Integrated test cases
109
-
110
- ## Running Tests
111
-
112
- Tests __must__ be run inside the Docker container:
113
-
114
- ````bash
115
- # Run all tests inside the container
116
- $ docker exec fastapi-psql-orm-app-1 bash scripts/test.sh
117
-
118
- # Run specific test file (example)
119
- $ docker exec fastapi-psql-orm-app-1 bash -c "cd /app && pytest tests/test_items.py -v"
120
- ````
121
-
122
- ## Database Management
123
-
124
- After making a new database's change, you must migrate it.
125
-
126
- ````bash
127
- # Apply database migrations
128
- $ docker exec fastapi-psql-orm-app-1 bash -c "alembic upgrade head"
129
-
130
- # Create new migrations
131
- $ docker exec fastapi-psql-orm-app-1 bash -c "alembic revision --autogenerate -m 'description'"
132
- ````
133
-
134
- For other FastAPI guides, please refer <https://fastapi.tiangolo.com/tutorial/>
135
-
136
- # Project Origin
137
-
138
- This project was created based on the template from the [FastAPI-fastkit](https://github.com/bnbong/FastAPI-fastkit) project.
139
-
140
- The `FastAPI-fastkit` is an open-source project that helps Python and FastAPI beginners quickly set up a FastAPI-based application development environment in a framework-like structure.
141
-
142
- ### Template Information
143
- - Template creator: [bnbong](mailto:bbbong9@gmail.com)
144
- - FastAPI-fastkit project maintainer: [bnbong](mailto:bbbong9@gmail.com)
1
+ # Dockerized FastAPI Item Management API with PostgreSQL
2
+
3
+ This project is a Docker containerized FastAPI-based item management API application with PostgreSQL database integration.
4
+
5
+ ## Requirements
6
+
7
+ - Docker and Docker Compose
8
+
9
+ ## Tech Stack
10
+
11
+ - Python 3.12+
12
+ - FastAPI + uvicorn
13
+ - PostgreSQL
14
+ - SQLModel (SQLAlchemy + Pydantic)
15
+ - Alembic
16
+ - Docker & Docker Compose
17
+ - pytest
18
+ - mypy + black + isort
19
+
20
+ ## Project Structure
21
+
22
+ ````
23
+ .
24
+ ├── Dockerfile
25
+ ├── README.md
26
+ ├── docker-compose.yml
27
+ ├── requirements.txt
28
+ ├── setup.py
29
+ ├── alembic.ini
30
+ ├── scripts
31
+ │ ├── pre-start.sh
32
+ │ └── test.sh
33
+ ├── src
34
+ │ ├── api
35
+ │ │ ├── api.py
36
+ │ │ ├── deps.py
37
+ │ │ └── routes
38
+ │ │ └── items.py
39
+ │ ├── core
40
+ │ │ ├── config.py
41
+ │ │ └── db.py
42
+ │ ├── crud
43
+ │ │ └── items.py
44
+ │ ├── alembic
45
+ │ │ ├── env.py
46
+ │ │ └── versions/
47
+ │ ├── schemas
48
+ │ │ └── items.py
49
+ │ ├── utils
50
+ │ │ ├── backend_pre_start.py
51
+ │ │ ├── init_data.py
52
+ │ │ └── tests_pre_start.py
53
+ │ └── main.py
54
+ └── tests
55
+ ├── __init__.py
56
+ ├── test_items.py
57
+ └── conftest.py
58
+ ````
59
+
60
+
61
+ ## How to Run
62
+
63
+ ### Run with Docker
64
+
65
+ ````bash
66
+ # Build and run with Docker Compose
67
+ $ docker-compose up -d
68
+
69
+ # Check container status
70
+ $ docker-compose ps
71
+ ````
72
+
73
+
74
+ Once the containers are running, you can check the API documentation at:
75
+
76
+ ````
77
+ http://localhost:8000/docs # Swagger format
78
+ http://localhost:8000/redoc # ReDoc format
79
+ ````
80
+
81
+
82
+ ### Run in Development Mode (Inside Container)
83
+
84
+ ````bash
85
+ # Run the application in development mode (using `--reload` option)
86
+ $ docker-compose exec app uvicorn src.main:app --reload --host 0.0.0.0
87
+ ````
88
+
89
+
90
+ ## API Endpoints
91
+
92
+ | Method | Endpoint | Description |
93
+ |--------|------------------|----------------------------|
94
+ | GET | `/items/` | List all items |
95
+ | GET | `/items/{id}` | Get single item |
96
+ | POST | `/items/` | Create new item |
97
+ | PUT | `/items/{id}` | Update existing item |
98
+ | DELETE | `/items/{id}` | Delete item |
99
+
100
+ ## Key Features
101
+
102
+ - Persistent storage using PostgreSQL database
103
+ - Database migrations using Alembic
104
+ - ORM using SQLModel (SQLAlchemy + Pydantic)
105
+ - Full containerization via Docker Compose
106
+ - Automatic loading of initial sample data
107
+ - Pydantic model-based data validation
108
+ - Integrated test cases
109
+
110
+ ## Running Tests
111
+
112
+ Tests __must__ be run inside the Docker container:
113
+
114
+ ````bash
115
+ # Run all tests inside the container
116
+ $ docker exec fastapi-psql-orm-app-1 bash scripts/test.sh
117
+
118
+ # Run specific test file (example)
119
+ $ docker exec fastapi-psql-orm-app-1 bash -c "cd /app && pytest tests/test_items.py -v"
120
+ ````
121
+
122
+ ## Database Management
123
+
124
+ After making a new database's change, you must migrate it.
125
+
126
+ ````bash
127
+ # Apply database migrations
128
+ $ docker exec fastapi-psql-orm-app-1 bash -c "alembic upgrade head"
129
+
130
+ # Create new migrations
131
+ $ docker exec fastapi-psql-orm-app-1 bash -c "alembic revision --autogenerate -m 'description'"
132
+ ````
133
+
134
+ For other FastAPI guides, please refer <https://fastapi.tiangolo.com/tutorial/>
135
+
136
+ # Project Origin
137
+
138
+ This project was created based on the template from the [FastAPI-fastkit](https://github.com/bnbong/FastAPI-fastkit) project.
139
+
140
+ The `FastAPI-fastkit` is an open-source project that helps Python and FastAPI beginners quickly set up a FastAPI-based application development environment in a framework-like structure.
141
+
142
+ ### Template Information
143
+ - Template creator: [bnbong](mailto:bbbong9@gmail.com)
144
+ - FastAPI-fastkit project maintainer: [bnbong](mailto:bbbong9@gmail.com)