fapilot 0.1.0__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.
- fapilot-0.1.0/CHANGELOG.md +17 -0
- fapilot-0.1.0/LICENSE +21 -0
- fapilot-0.1.0/MANIFEST.in +11 -0
- fapilot-0.1.0/PKG-INFO +134 -0
- fapilot-0.1.0/README.md +87 -0
- fapilot-0.1.0/SECURITY.md +19 -0
- fapilot-0.1.0/fapilot/__init__.py +5 -0
- fapilot-0.1.0/fapilot/apps/__init__.py +5 -0
- fapilot-0.1.0/fapilot/apps/config.py +31 -0
- fapilot-0.1.0/fapilot/apps/registry.py +43 -0
- fapilot-0.1.0/fapilot/auth/__init__.py +5 -0
- fapilot-0.1.0/fapilot/auth/jwt.py +30 -0
- fapilot-0.1.0/fapilot/auth/passwords.py +14 -0
- fapilot-0.1.0/fapilot/background/__init__.py +4 -0
- fapilot-0.1.0/fapilot/background/tasks.py +15 -0
- fapilot-0.1.0/fapilot/cli.py +218 -0
- fapilot-0.1.0/fapilot/conf/__init__.py +4 -0
- fapilot-0.1.0/fapilot/conf/settings.py +65 -0
- fapilot-0.1.0/fapilot/core/application.py +75 -0
- fapilot-0.1.0/fapilot/crud.py +43 -0
- fapilot-0.1.0/fapilot/db/__init__.py +4 -0
- fapilot-0.1.0/fapilot/db/migrations.py +42 -0
- fapilot-0.1.0/fapilot/db/tortoise.py +28 -0
- fapilot-0.1.0/fapilot/events/__init__.py +4 -0
- fapilot-0.1.0/fapilot/events/dispatcher.py +23 -0
- fapilot-0.1.0/fapilot/exceptions.py +10 -0
- fapilot-0.1.0/fapilot/filtering.py +8 -0
- fapilot-0.1.0/fapilot/management/__init__.py +1 -0
- fapilot-0.1.0/fapilot/management/commands.py +15 -0
- fapilot-0.1.0/fapilot/middleware.py +19 -0
- fapilot-0.1.0/fapilot/pagination.py +35 -0
- fapilot-0.1.0/fapilot/permissions/__init__.py +4 -0
- fapilot-0.1.0/fapilot/permissions/base.py +26 -0
- fapilot-0.1.0/fapilot/py.typed +1 -0
- fapilot-0.1.0/fapilot/realtime/__init__.py +5 -0
- fapilot-0.1.0/fapilot/realtime/sse.py +25 -0
- fapilot-0.1.0/fapilot/realtime/websockets.py +26 -0
- fapilot-0.1.0/fapilot/responses.py +10 -0
- fapilot-0.1.0/fapilot/testing/__init__.py +4 -0
- fapilot-0.1.0/fapilot/testing/client.py +17 -0
- fapilot-0.1.0/fapilot.egg-info/SOURCES.txt +40 -0
- fapilot-0.1.0/pyproject.toml +87 -0
- fapilot-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to Fapilot will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on Keep a Changelog, and this project follows semantic
|
|
6
|
+
versioning before the public API reaches 1.0.
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-09-06
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Initial Fapilot package with Django-inspired project and app scaffolding.
|
|
13
|
+
- FastAPI application factory, settings loader, app registry, middleware helpers,
|
|
14
|
+
permissions, pagination, filtering, CRUD utilities, realtime helpers, and
|
|
15
|
+
Aerich/Tortoise integration.
|
|
16
|
+
- `fapilot` CLI with `startproject`, `startapp`, `makemigrations`, `migrate`,
|
|
17
|
+
and `runserver` commands.
|
fapilot-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fapilot maintainers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md
|
|
3
|
+
include CHANGELOG.md
|
|
4
|
+
include SECURITY.md
|
|
5
|
+
include fapilot/py.typed
|
|
6
|
+
recursive-include fapilot *.py
|
|
7
|
+
recursive-exclude * __pycache__
|
|
8
|
+
recursive-exclude * *.py[cod]
|
|
9
|
+
prune tests
|
|
10
|
+
prune .github
|
|
11
|
+
prune fapilot.egg-info
|
fapilot-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: fapilot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Django-inspired async application framework built on FastAPI, Tortoise ORM, and Aerich.
|
|
5
|
+
Author: Ali Hajiali
|
|
6
|
+
Maintainer: Ali Hajiali
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/alihajiali/fapilot
|
|
9
|
+
Project-URL: Repository, https://github.com/alihajiali/fapilot
|
|
10
|
+
Project-URL: Issues, https://github.com/alihajiali/fapilot/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/alihajiali/fapilot/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: fastapi,async,framework,tortoise-orm,aerich,django-inspired
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Web Environment
|
|
15
|
+
Classifier: Framework :: FastAPI
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.12
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: fastapi<0.142,>=0.141
|
|
30
|
+
Requires-Dist: starlette<0.50,>=0.49
|
|
31
|
+
Requires-Dist: pydantic<3,>=2.12
|
|
32
|
+
Requires-Dist: pydantic-settings<3,>=2.10
|
|
33
|
+
Requires-Dist: tortoise-orm[asyncpg]<1.2,>=1.1
|
|
34
|
+
Requires-Dist: aerich[toml]<0.11,>=0.10
|
|
35
|
+
Requires-Dist: uvicorn[standard]<0.36,>=0.35
|
|
36
|
+
Requires-Dist: python-jose<4,>=3.5
|
|
37
|
+
Requires-Dist: passlib[bcrypt]<2,>=1.7
|
|
38
|
+
Requires-Dist: python-multipart<0.0.21,>=0.0.20
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: build<2,>=1.3; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest<9,>=8.4; extra == "dev"
|
|
42
|
+
Requires-Dist: pytest-anyio>=0.0.0; extra == "dev"
|
|
43
|
+
Requires-Dist: httpx<0.29,>=0.28; extra == "dev"
|
|
44
|
+
Requires-Dist: ruff<0.13,>=0.12; extra == "dev"
|
|
45
|
+
Requires-Dist: pyright<2,>=1.1; extra == "dev"
|
|
46
|
+
Requires-Dist: twine<7,>=6.2; extra == "dev"
|
|
47
|
+
|
|
48
|
+
# Fapilot
|
|
49
|
+
|
|
50
|
+
Fapilot is an opinionated, async-first backend framework built on FastAPI. It borrows Django's project organization, app registry, settings discipline, scaffolding, and management-command ergonomics while keeping FastAPI's dependency injection, OpenAPI, lifespan, and async runtime model.
|
|
51
|
+
|
|
52
|
+
## Features
|
|
53
|
+
|
|
54
|
+
- Django-inspired project and app scaffolding.
|
|
55
|
+
- FastAPI application factory with app registry integration.
|
|
56
|
+
- Pydantic settings loader with uppercase application settings.
|
|
57
|
+
- Tortoise ORM configuration and Aerich migration backend.
|
|
58
|
+
- Pagination, filtering, CRUD, permissions, middleware, events, auth, and realtime helpers.
|
|
59
|
+
- CLI commands for project creation, app creation, migrations, and local serving.
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
For local development from this repository:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
python3.12 -m venv .venv
|
|
67
|
+
source .venv/bin/activate
|
|
68
|
+
python -m pip install -U pip
|
|
69
|
+
python -m pip install -e ".[dev]"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
After installation, the `fapilot` command is available on your shell path:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
fapilot --help
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
You can also run the CLI directly from a checkout:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
python3.12 -m fapilot.cli --help
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Quick Start
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
python3.12 -m pip install -e .
|
|
88
|
+
fapilot startproject myproject
|
|
89
|
+
cd myproject
|
|
90
|
+
fapilot startapp users
|
|
91
|
+
fapilot makemigrations
|
|
92
|
+
fapilot migrate
|
|
93
|
+
fapilot runserver
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Core stack:
|
|
97
|
+
|
|
98
|
+
- FastAPI + Starlette lifespan
|
|
99
|
+
- Pydantic v2 + pydantic-settings
|
|
100
|
+
- Tortoise ORM
|
|
101
|
+
- Aerich migrations through a backend abstraction
|
|
102
|
+
- Uvicorn
|
|
103
|
+
- pytest, HTTPX, AnyIO
|
|
104
|
+
- Ruff and Pyright
|
|
105
|
+
|
|
106
|
+
This repository contains the reusable framework package. Generated projects contain `config/`, `apps/`, `common/`, `manage.py`, Docker files, `.env`, and a project-local `pyproject.toml`.
|
|
107
|
+
|
|
108
|
+
## CLI
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
fapilot startproject myproject
|
|
112
|
+
fapilot startapp users
|
|
113
|
+
fapilot makemigrations --name initial
|
|
114
|
+
fapilot migrate
|
|
115
|
+
fapilot runserver --host 127.0.0.1 --port 8000
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Development
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
ruff check .
|
|
122
|
+
pyright
|
|
123
|
+
pytest
|
|
124
|
+
python -m build
|
|
125
|
+
twine check dist/*
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Release
|
|
129
|
+
|
|
130
|
+
See [RELEASE.md](RELEASE.md) for the release checklist and PyPI publishing flow.
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
Fapilot is released under the MIT License. See [LICENSE](LICENSE).
|
fapilot-0.1.0/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Fapilot
|
|
2
|
+
|
|
3
|
+
Fapilot is an opinionated, async-first backend framework built on FastAPI. It borrows Django's project organization, app registry, settings discipline, scaffolding, and management-command ergonomics while keeping FastAPI's dependency injection, OpenAPI, lifespan, and async runtime model.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Django-inspired project and app scaffolding.
|
|
8
|
+
- FastAPI application factory with app registry integration.
|
|
9
|
+
- Pydantic settings loader with uppercase application settings.
|
|
10
|
+
- Tortoise ORM configuration and Aerich migration backend.
|
|
11
|
+
- Pagination, filtering, CRUD, permissions, middleware, events, auth, and realtime helpers.
|
|
12
|
+
- CLI commands for project creation, app creation, migrations, and local serving.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
For local development from this repository:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
python3.12 -m venv .venv
|
|
20
|
+
source .venv/bin/activate
|
|
21
|
+
python -m pip install -U pip
|
|
22
|
+
python -m pip install -e ".[dev]"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
After installation, the `fapilot` command is available on your shell path:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
fapilot --help
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
You can also run the CLI directly from a checkout:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python3.12 -m fapilot.cli --help
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
python3.12 -m pip install -e .
|
|
41
|
+
fapilot startproject myproject
|
|
42
|
+
cd myproject
|
|
43
|
+
fapilot startapp users
|
|
44
|
+
fapilot makemigrations
|
|
45
|
+
fapilot migrate
|
|
46
|
+
fapilot runserver
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Core stack:
|
|
50
|
+
|
|
51
|
+
- FastAPI + Starlette lifespan
|
|
52
|
+
- Pydantic v2 + pydantic-settings
|
|
53
|
+
- Tortoise ORM
|
|
54
|
+
- Aerich migrations through a backend abstraction
|
|
55
|
+
- Uvicorn
|
|
56
|
+
- pytest, HTTPX, AnyIO
|
|
57
|
+
- Ruff and Pyright
|
|
58
|
+
|
|
59
|
+
This repository contains the reusable framework package. Generated projects contain `config/`, `apps/`, `common/`, `manage.py`, Docker files, `.env`, and a project-local `pyproject.toml`.
|
|
60
|
+
|
|
61
|
+
## CLI
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
fapilot startproject myproject
|
|
65
|
+
fapilot startapp users
|
|
66
|
+
fapilot makemigrations --name initial
|
|
67
|
+
fapilot migrate
|
|
68
|
+
fapilot runserver --host 127.0.0.1 --port 8000
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Development
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
ruff check .
|
|
75
|
+
pyright
|
|
76
|
+
pytest
|
|
77
|
+
python -m build
|
|
78
|
+
twine check dist/*
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Release
|
|
82
|
+
|
|
83
|
+
See [RELEASE.md](RELEASE.md) for the release checklist and PyPI publishing flow.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
Fapilot is released under the MIT License. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported versions
|
|
4
|
+
|
|
5
|
+
Fapilot is currently pre-1.0. Security fixes are provided for the latest
|
|
6
|
+
released version.
|
|
7
|
+
|
|
8
|
+
## Reporting a vulnerability
|
|
9
|
+
|
|
10
|
+
Please do not open a public issue for suspected vulnerabilities.
|
|
11
|
+
|
|
12
|
+
Email the maintainers or use GitHub private vulnerability reporting if it is
|
|
13
|
+
enabled for the repository. Include:
|
|
14
|
+
|
|
15
|
+
- Affected version or commit.
|
|
16
|
+
- Steps to reproduce.
|
|
17
|
+
- Impact and any known workarounds.
|
|
18
|
+
|
|
19
|
+
We aim to acknowledge reports within 72 hours.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from fastapi import APIRouter
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass(slots=True)
|
|
10
|
+
class AppConfig:
|
|
11
|
+
name: str
|
|
12
|
+
label: str | None = None
|
|
13
|
+
verbose_name: str | None = None
|
|
14
|
+
router: APIRouter | None = None
|
|
15
|
+
router_prefix: str | None = None
|
|
16
|
+
tortoise_models: list[str] = field(default_factory=list)
|
|
17
|
+
migrations_package: str | None = None
|
|
18
|
+
|
|
19
|
+
def ready(self) -> None:
|
|
20
|
+
"""Hook called after every app is imported and registered."""
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def app_label(self) -> str:
|
|
24
|
+
return self.label or self.name.rsplit(".", 1)[-1]
|
|
25
|
+
|
|
26
|
+
def as_tortoise_app(self) -> dict[str, Any]:
|
|
27
|
+
models = [*self.tortoise_models]
|
|
28
|
+
if self.migrations_package is not None:
|
|
29
|
+
models.append(self.migrations_package)
|
|
30
|
+
return {"models": models, "default_connection": "default"}
|
|
31
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterable
|
|
4
|
+
from importlib import import_module
|
|
5
|
+
|
|
6
|
+
from fapilot.apps.config import AppConfig
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AppRegistry:
|
|
10
|
+
def __init__(self) -> None:
|
|
11
|
+
self._apps: dict[str, AppConfig] = {}
|
|
12
|
+
self.ready = False
|
|
13
|
+
|
|
14
|
+
def populate(self, installed_apps: Iterable[str]) -> None:
|
|
15
|
+
if self.ready:
|
|
16
|
+
return
|
|
17
|
+
for dotted_path in installed_apps:
|
|
18
|
+
app_config = self._load_config(dotted_path)
|
|
19
|
+
label = app_config.app_label
|
|
20
|
+
if label in self._apps:
|
|
21
|
+
raise RuntimeError(f"Duplicate app label: {label}")
|
|
22
|
+
self._apps[label] = app_config
|
|
23
|
+
for app_config in self._apps.values():
|
|
24
|
+
app_config.ready()
|
|
25
|
+
self.ready = True
|
|
26
|
+
|
|
27
|
+
def get_app(self, label: str) -> AppConfig:
|
|
28
|
+
return self._apps[label]
|
|
29
|
+
|
|
30
|
+
def get_apps(self) -> list[AppConfig]:
|
|
31
|
+
return list(self._apps.values())
|
|
32
|
+
|
|
33
|
+
def _load_config(self, dotted_path: str) -> AppConfig:
|
|
34
|
+
module_path, _, class_name = dotted_path.rpartition(".")
|
|
35
|
+
if not module_path:
|
|
36
|
+
module_path = f"{dotted_path}.apps"
|
|
37
|
+
class_name = "Config"
|
|
38
|
+
module = import_module(module_path)
|
|
39
|
+
config_cls = getattr(module, class_name)
|
|
40
|
+
config = config_cls()
|
|
41
|
+
if not isinstance(config, AppConfig):
|
|
42
|
+
raise TypeError(f"{dotted_path} must instantiate fapilot.apps.AppConfig")
|
|
43
|
+
return config
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import UTC, datetime, timedelta
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from jose import JWTError, jwt
|
|
7
|
+
|
|
8
|
+
from fapilot.conf import get_settings
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def create_access_token(subject: str, claims: dict[str, Any] | None = None) -> str:
|
|
12
|
+
settings = get_settings()
|
|
13
|
+
jwt_settings = settings.JWT_SETTINGS
|
|
14
|
+
expires_at = datetime.now(UTC) + timedelta(minutes=jwt_settings.access_token_expire_minutes)
|
|
15
|
+
payload = {
|
|
16
|
+
"sub": subject,
|
|
17
|
+
"iss": jwt_settings.issuer,
|
|
18
|
+
"exp": expires_at,
|
|
19
|
+
**(claims or {}),
|
|
20
|
+
}
|
|
21
|
+
return jwt.encode(payload, settings.SECRET_KEY, algorithm=jwt_settings.algorithm)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def decode_access_token(token: str) -> dict[str, Any] | None:
|
|
25
|
+
settings = get_settings()
|
|
26
|
+
try:
|
|
27
|
+
return jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.JWT_SETTINGS.algorithm])
|
|
28
|
+
except JWTError:
|
|
29
|
+
return None
|
|
30
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from passlib.context import CryptContext
|
|
4
|
+
|
|
5
|
+
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def hash_password(password: str) -> str:
|
|
9
|
+
return pwd_context.hash(password)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def verify_password(password: str, hashed_password: str) -> bool:
|
|
13
|
+
return pwd_context.verify(password, hashed_password)
|
|
14
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from collections.abc import Callable, Coroutine
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TaskQueue:
|
|
9
|
+
def spawn(
|
|
10
|
+
self,
|
|
11
|
+
func: Callable[..., Coroutine[Any, Any, Any]],
|
|
12
|
+
*args: Any,
|
|
13
|
+
**kwargs: Any,
|
|
14
|
+
) -> asyncio.Task:
|
|
15
|
+
return asyncio.create_task(func(*args, **kwargs))
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import subprocess
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from fapilot.db.migrations import AerichMigrationBackend
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main() -> None:
|
|
11
|
+
parser = argparse.ArgumentParser(prog="fapilot")
|
|
12
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
13
|
+
startproject = subparsers.add_parser("startproject")
|
|
14
|
+
startproject.add_argument("name")
|
|
15
|
+
startapp = subparsers.add_parser("startapp")
|
|
16
|
+
startapp.add_argument("name")
|
|
17
|
+
makemigrations = subparsers.add_parser("makemigrations")
|
|
18
|
+
makemigrations.add_argument("--name")
|
|
19
|
+
subparsers.add_parser("migrate")
|
|
20
|
+
runserver = subparsers.add_parser("runserver")
|
|
21
|
+
runserver.add_argument("--host", default="127.0.0.1")
|
|
22
|
+
runserver.add_argument("--port", default="8000")
|
|
23
|
+
args = parser.parse_args()
|
|
24
|
+
|
|
25
|
+
if args.command == "startproject":
|
|
26
|
+
start_project(args.name)
|
|
27
|
+
elif args.command == "startapp":
|
|
28
|
+
start_app(args.name)
|
|
29
|
+
elif args.command == "makemigrations":
|
|
30
|
+
AerichMigrationBackend().makemigrations(args.name)
|
|
31
|
+
elif args.command == "migrate":
|
|
32
|
+
AerichMigrationBackend().migrate()
|
|
33
|
+
elif args.command == "runserver":
|
|
34
|
+
subprocess.run(
|
|
35
|
+
["uvicorn", "config.asgi:app", "--host", args.host, "--port", args.port, "--reload"],
|
|
36
|
+
check=True,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def start_project(name: str) -> None:
|
|
41
|
+
root = Path(name)
|
|
42
|
+
root.mkdir()
|
|
43
|
+
for directory in ["config", "apps", "common", "tests"]:
|
|
44
|
+
(root / directory).mkdir()
|
|
45
|
+
(root / directory / "__init__.py").write_text("", encoding="utf-8")
|
|
46
|
+
_write(root / "manage.py", MANAGE)
|
|
47
|
+
_write(root / "config/settings.py", SETTINGS)
|
|
48
|
+
_write(root / "config/database.py", DATABASE)
|
|
49
|
+
_write(root / "config/urls.py", URLS)
|
|
50
|
+
_write(root / "config/asgi.py", ASGI)
|
|
51
|
+
_write(root / "config/logging.py", "LOGGING = {}\n")
|
|
52
|
+
_write(root / "common/crud.py", "from fapilot.crud import CRUDRouterService\n")
|
|
53
|
+
_write(root / "common/pagination.py", "from fapilot.pagination import Page, Pagination\n")
|
|
54
|
+
_write(root / "common/filtering.py", "from fapilot.filtering import pick_filters\n")
|
|
55
|
+
_write(root / "common/exceptions.py", "from fapilot.exceptions import FapilotError\n")
|
|
56
|
+
_write(
|
|
57
|
+
root / "common/permissions.py",
|
|
58
|
+
"from fapilot.permissions import AllowAny, IsAuthenticated\n",
|
|
59
|
+
)
|
|
60
|
+
_write(root / "common/middleware.py", "from fapilot.middleware import install_cors\n")
|
|
61
|
+
_write(root / "common/responses.py", "from fapilot.responses import ok\n")
|
|
62
|
+
_write(root / "common/events.py", "from fapilot.events import SignalDispatcher\n")
|
|
63
|
+
_write(root / "common/models.py", "from tortoise import fields, models\n")
|
|
64
|
+
_write(root / "common/schemas.py", "from pydantic import BaseModel, ConfigDict\n")
|
|
65
|
+
_write(root / "common/utils.py", "\n")
|
|
66
|
+
_write(root / ".env", ENV)
|
|
67
|
+
_write(root / ".env.example", ENV)
|
|
68
|
+
_write(root / ".gitignore", GITIGNORE)
|
|
69
|
+
_write(root / "README.md", PROJECT_README.format(name=name))
|
|
70
|
+
_write(root / "Dockerfile", DOCKERFILE)
|
|
71
|
+
_write(root / "docker-compose.yml", COMPOSE)
|
|
72
|
+
_write(root / "pyproject.toml", PROJECT_PYPROJECT.format(name=name))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def start_app(name: str) -> None:
|
|
76
|
+
app_dir = Path("apps") / name
|
|
77
|
+
app_dir.mkdir(parents=True)
|
|
78
|
+
(app_dir / "tests").mkdir()
|
|
79
|
+
(app_dir / "migrations").mkdir()
|
|
80
|
+
for file_name, content in APP_FILES.items():
|
|
81
|
+
class_name = name.title().replace("_", "")
|
|
82
|
+
_write(app_dir / file_name, content.format(name=name, class_name=class_name))
|
|
83
|
+
_write(app_dir / "tests/__init__.py", "")
|
|
84
|
+
_write(app_dir / "migrations/__init__.py", "")
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _write(path: Path, content: str) -> None:
|
|
88
|
+
path.write_text(content, encoding="utf-8")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
MANAGE = """#!/usr/bin/env python
|
|
92
|
+
from fapilot.cli import main
|
|
93
|
+
|
|
94
|
+
if __name__ == "__main__":
|
|
95
|
+
main()
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
SETTINGS = '''from fapilot.conf import FapilotSettings
|
|
99
|
+
|
|
100
|
+
DEBUG = True
|
|
101
|
+
SECRET_KEY = "change-me"
|
|
102
|
+
ALLOWED_HOSTS = ["localhost", "127.0.0.1"]
|
|
103
|
+
DATABASE_URL = "sqlite://db.sqlite3"
|
|
104
|
+
INSTALLED_APPS = []
|
|
105
|
+
MIDDLEWARE = ["common.middleware.install_cors"]
|
|
106
|
+
CORS_ALLOWED_ORIGINS = []
|
|
107
|
+
TIME_ZONE = "UTC"
|
|
108
|
+
LANGUAGE_CODE = "en-us"
|
|
109
|
+
API_PREFIX = "/api"
|
|
110
|
+
DEFAULT_PAGE_SIZE = 20
|
|
111
|
+
MAX_PAGE_SIZE = 100
|
|
112
|
+
AUTH_USER_MODEL = "users.User"
|
|
113
|
+
JWT_SETTINGS = FapilotSettings().JWT_SETTINGS
|
|
114
|
+
LOGGING = {}
|
|
115
|
+
'''
|
|
116
|
+
|
|
117
|
+
DATABASE = """import os
|
|
118
|
+
|
|
119
|
+
from fapilot.apps import AppRegistry
|
|
120
|
+
from fapilot.conf import load_settings
|
|
121
|
+
from fapilot.db.tortoise import build_tortoise_config
|
|
122
|
+
|
|
123
|
+
settings = load_settings("config.settings")
|
|
124
|
+
registry = AppRegistry()
|
|
125
|
+
registry.populate(settings.INSTALLED_APPS)
|
|
126
|
+
TORTOISE_ORM = build_tortoise_config(settings, registry)
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
URLS = """from fastapi import APIRouter
|
|
130
|
+
|
|
131
|
+
router = APIRouter()
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
ASGI = """import os
|
|
135
|
+
|
|
136
|
+
from fapilot import create_app
|
|
137
|
+
from fapilot.conf import load_settings
|
|
138
|
+
|
|
139
|
+
os.environ.setdefault("FAPILOT_SETTINGS_MODULE", "config.settings")
|
|
140
|
+
app = create_app(load_settings("config.settings"))
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
ENV = """DEBUG=true
|
|
144
|
+
SECRET_KEY=change-me
|
|
145
|
+
DATABASE_URL=sqlite://db.sqlite3
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
GITIGNORE = """.venv/
|
|
149
|
+
__pycache__/
|
|
150
|
+
.env
|
|
151
|
+
db.sqlite3
|
|
152
|
+
.ruff_cache/
|
|
153
|
+
.pytest_cache/
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
PROJECT_README = """# {name}
|
|
157
|
+
|
|
158
|
+
Generated by Fapilot.
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
uv sync
|
|
162
|
+
fapilot startapp users
|
|
163
|
+
fapilot runserver
|
|
164
|
+
```
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
PROJECT_PYPROJECT = '''[project]
|
|
168
|
+
name = "{name}"
|
|
169
|
+
version = "0.1.0"
|
|
170
|
+
requires-python = ">=3.12"
|
|
171
|
+
dependencies = ["fapilot"]
|
|
172
|
+
|
|
173
|
+
[tool.aerich]
|
|
174
|
+
tortoise_orm = "config.database.TORTOISE_ORM"
|
|
175
|
+
location = "./migrations"
|
|
176
|
+
src_folder = "."
|
|
177
|
+
'''
|
|
178
|
+
|
|
179
|
+
DOCKERFILE = """FROM python:3.12-slim
|
|
180
|
+
WORKDIR /app
|
|
181
|
+
COPY . .
|
|
182
|
+
RUN pip install fapilot
|
|
183
|
+
CMD ["uvicorn", "config.asgi:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
184
|
+
"""
|
|
185
|
+
|
|
186
|
+
COMPOSE = """services:
|
|
187
|
+
postgres:
|
|
188
|
+
image: postgres:16
|
|
189
|
+
environment:
|
|
190
|
+
POSTGRES_DB: app
|
|
191
|
+
POSTGRES_USER: app
|
|
192
|
+
POSTGRES_PASSWORD: app
|
|
193
|
+
ports:
|
|
194
|
+
- "5432:5432"
|
|
195
|
+
"""
|
|
196
|
+
|
|
197
|
+
APP_FILES = {
|
|
198
|
+
"__init__.py": "",
|
|
199
|
+
"apps.py": """from fapilot.apps import AppConfig
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
class {class_name}Config(AppConfig):
|
|
203
|
+
def __init__(self) -> None:
|
|
204
|
+
super().__init__(name="apps.{name}", label="{name}")
|
|
205
|
+
""",
|
|
206
|
+
"models.py": "from tortoise import fields, models\n\n\n# Define models here.\n",
|
|
207
|
+
"schemas.py": "from pydantic import BaseModel, ConfigDict\n\n\n# Define schemas here.\n",
|
|
208
|
+
"api.py": """from fastapi import APIRouter
|
|
209
|
+
|
|
210
|
+
router = APIRouter()
|
|
211
|
+
""",
|
|
212
|
+
"services.py": "",
|
|
213
|
+
"repositories.py": "",
|
|
214
|
+
"permissions.py": "from fapilot.permissions import AllowAny, IsAuthenticated\n",
|
|
215
|
+
"dependencies.py": "",
|
|
216
|
+
"signals.py": "",
|
|
217
|
+
"admin.py": "",
|
|
218
|
+
}
|