fapier 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.
- fapier-0.1.0/PKG-INFO +160 -0
- fapier-0.1.0/README.md +140 -0
- fapier-0.1.0/fapi/__init__.py +0 -0
- fapier-0.1.0/fapi/cli.py +10 -0
- fapier-0.1.0/fapi/commands/__init__.py +0 -0
- fapier-0.1.0/fapi/commands/add.py +124 -0
- fapier-0.1.0/fapi/commands/create.py +86 -0
- fapier-0.1.0/fapi/constants.py +4 -0
- fapier-0.1.0/fapi/utils/__init__.py +0 -0
- fapier-0.1.0/fapi/utils/ustils.py +32 -0
- fapier-0.1.0/fapier.egg-info/PKG-INFO +160 -0
- fapier-0.1.0/fapier.egg-info/SOURCES.txt +16 -0
- fapier-0.1.0/fapier.egg-info/dependency_links.txt +1 -0
- fapier-0.1.0/fapier.egg-info/entry_points.txt +2 -0
- fapier-0.1.0/fapier.egg-info/requires.txt +9 -0
- fapier-0.1.0/fapier.egg-info/top_level.txt +1 -0
- fapier-0.1.0/pyproject.toml +33 -0
- fapier-0.1.0/setup.cfg +4 -0
fapier-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fapier
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A command-line tool to scaffold and bootstrap FastAPI projects quickly.
|
|
5
|
+
Author: Dahmoun Mouaine Aymen
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/aymen-dahmoun/fapi
|
|
8
|
+
Project-URL: Repository, https://github.com/aymen-dahmoun/fapi
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: fastapi
|
|
12
|
+
Requires-Dist: uvicorn[standard]
|
|
13
|
+
Requires-Dist: typer[all]
|
|
14
|
+
Requires-Dist: jinja2
|
|
15
|
+
Requires-Dist: sqlalchemy
|
|
16
|
+
Requires-Dist: passlib[bcrypt]
|
|
17
|
+
Requires-Dist: pydantic[email]
|
|
18
|
+
Requires-Dist: python-dotenv
|
|
19
|
+
Requires-Dist: pydantic-settings
|
|
20
|
+
|
|
21
|
+
# FastAPI Project Generator CLI
|
|
22
|
+
|
|
23
|
+
A CLI tool that scaffolds FastAPI projects with optional database and API structure.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## ✅ Features
|
|
28
|
+
|
|
29
|
+
| Feature | Description |
|
|
30
|
+
| -------------------------- | ----------------------------------------------- |
|
|
31
|
+
| Generate FastAPI project | Creates a full FastAPI folder structure |
|
|
32
|
+
| Optional Database | Create project with or without SQLAlchemy setup |
|
|
33
|
+
| Auto-creates virtualenv | Creates `.venv` inside the project |
|
|
34
|
+
| Auto-installs requirements | Installs dependencies based on options |
|
|
35
|
+
| Jinja2 Templates | Clean and flexible template system |
|
|
36
|
+
| Developer friendly | Simple prompts & automatic setup |
|
|
37
|
+
| CLI `add` commands | Add routes, models, schemas, crud, services |
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 📂 Project Output Structure
|
|
42
|
+
|
|
43
|
+
When DB and routes are enabled:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
project_name/
|
|
47
|
+
├─ app/
|
|
48
|
+
│ ├─ main.py
|
|
49
|
+
│ ├─ core/
|
|
50
|
+
│ │ └─ config.py
|
|
51
|
+
│ ├─ models/
|
|
52
|
+
│ │ └─ user.py
|
|
53
|
+
│ ├─ schemas/
|
|
54
|
+
│ │ └─ user.py
|
|
55
|
+
│ ├─ crud/
|
|
56
|
+
│ │ └─ user.py
|
|
57
|
+
│ ├─ services/
|
|
58
|
+
│ │ └─ example.py
|
|
59
|
+
│ ├─ api/
|
|
60
|
+
│ │ └─ router.py
|
|
61
|
+
│ └─ __init__.py
|
|
62
|
+
├─ .fastapi # internal flag to detect project
|
|
63
|
+
├─ .env
|
|
64
|
+
├─ requirements.txt
|
|
65
|
+
└─ .venv/
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
If database or routes are disabled, the tool skips those folders.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 🧰 Installation
|
|
73
|
+
|
|
74
|
+
### Clone Repo
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
git clone https://github.com/aymen-Dahmoun/FApi.git
|
|
78
|
+
cd FApi
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Install dependencies
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install -r requirements.txt
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
> Requires Python 3.10+
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 🚀 Usage
|
|
92
|
+
|
|
93
|
+
### Create a project
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
python cli.py myproject
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Answer prompts
|
|
100
|
+
|
|
101
|
+
Example interaction:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
Do you want to use a DB? [y/n]: y
|
|
105
|
+
Choose a Database (sqlite/postgres) [sqlite]: sqlite
|
|
106
|
+
Do you want to generate routes? [y/n]: y
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
or simply run
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
python cli.py myproject --db sqlite --routes
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Add new components
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
fapi add route product
|
|
119
|
+
fapi add model product --schema --crud
|
|
120
|
+
fapi add service payment
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
> Auto-detects if you're inside a FastAPI project using `.fastapi`
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 🏁 Run the project
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
cd myproject
|
|
131
|
+
source .venv/bin/activate # Linux/Mac
|
|
132
|
+
# or .venv\Scripts\activate on Windows
|
|
133
|
+
|
|
134
|
+
uvicorn app.main:app --reload
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## 📌 Roadmap
|
|
140
|
+
|
|
141
|
+
| Feature | Status |
|
|
142
|
+
| ---------------------- | ---------- |
|
|
143
|
+
| Basic FastAPI scaffold | ✅ Done |
|
|
144
|
+
| Optional DB | ✅ Done |
|
|
145
|
+
| Optional API | ✅ Done |
|
|
146
|
+
| `fapi add` commands | ✅ Done |
|
|
147
|
+
| Auto router import | 🔜 Planned |
|
|
148
|
+
| Alembic migrations | 🔜 Planned |
|
|
149
|
+
| Docker support | 🔜 Planned |
|
|
150
|
+
| Publish on PyPI | 🎯 Future |
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## 🤝 Contributing
|
|
155
|
+
|
|
156
|
+
Pull requests are welcome! 👐
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
⭐ If you like this tool, give the repo a star!
|
fapier-0.1.0/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# FastAPI Project Generator CLI
|
|
2
|
+
|
|
3
|
+
A CLI tool that scaffolds FastAPI projects with optional database and API structure.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ✅ Features
|
|
8
|
+
|
|
9
|
+
| Feature | Description |
|
|
10
|
+
| -------------------------- | ----------------------------------------------- |
|
|
11
|
+
| Generate FastAPI project | Creates a full FastAPI folder structure |
|
|
12
|
+
| Optional Database | Create project with or without SQLAlchemy setup |
|
|
13
|
+
| Auto-creates virtualenv | Creates `.venv` inside the project |
|
|
14
|
+
| Auto-installs requirements | Installs dependencies based on options |
|
|
15
|
+
| Jinja2 Templates | Clean and flexible template system |
|
|
16
|
+
| Developer friendly | Simple prompts & automatic setup |
|
|
17
|
+
| CLI `add` commands | Add routes, models, schemas, crud, services |
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 📂 Project Output Structure
|
|
22
|
+
|
|
23
|
+
When DB and routes are enabled:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
project_name/
|
|
27
|
+
├─ app/
|
|
28
|
+
│ ├─ main.py
|
|
29
|
+
│ ├─ core/
|
|
30
|
+
│ │ └─ config.py
|
|
31
|
+
│ ├─ models/
|
|
32
|
+
│ │ └─ user.py
|
|
33
|
+
│ ├─ schemas/
|
|
34
|
+
│ │ └─ user.py
|
|
35
|
+
│ ├─ crud/
|
|
36
|
+
│ │ └─ user.py
|
|
37
|
+
│ ├─ services/
|
|
38
|
+
│ │ └─ example.py
|
|
39
|
+
│ ├─ api/
|
|
40
|
+
│ │ └─ router.py
|
|
41
|
+
│ └─ __init__.py
|
|
42
|
+
├─ .fastapi # internal flag to detect project
|
|
43
|
+
├─ .env
|
|
44
|
+
├─ requirements.txt
|
|
45
|
+
└─ .venv/
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
If database or routes are disabled, the tool skips those folders.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 🧰 Installation
|
|
53
|
+
|
|
54
|
+
### Clone Repo
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
git clone https://github.com/aymen-Dahmoun/FApi.git
|
|
58
|
+
cd FApi
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Install dependencies
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install -r requirements.txt
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
> Requires Python 3.10+
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 🚀 Usage
|
|
72
|
+
|
|
73
|
+
### Create a project
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
python cli.py myproject
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Answer prompts
|
|
80
|
+
|
|
81
|
+
Example interaction:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
Do you want to use a DB? [y/n]: y
|
|
85
|
+
Choose a Database (sqlite/postgres) [sqlite]: sqlite
|
|
86
|
+
Do you want to generate routes? [y/n]: y
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
or simply run
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
python cli.py myproject --db sqlite --routes
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Add new components
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
fapi add route product
|
|
99
|
+
fapi add model product --schema --crud
|
|
100
|
+
fapi add service payment
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
> Auto-detects if you're inside a FastAPI project using `.fastapi`
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 🏁 Run the project
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
cd myproject
|
|
111
|
+
source .venv/bin/activate # Linux/Mac
|
|
112
|
+
# or .venv\Scripts\activate on Windows
|
|
113
|
+
|
|
114
|
+
uvicorn app.main:app --reload
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## 📌 Roadmap
|
|
120
|
+
|
|
121
|
+
| Feature | Status |
|
|
122
|
+
| ---------------------- | ---------- |
|
|
123
|
+
| Basic FastAPI scaffold | ✅ Done |
|
|
124
|
+
| Optional DB | ✅ Done |
|
|
125
|
+
| Optional API | ✅ Done |
|
|
126
|
+
| `fapi add` commands | ✅ Done |
|
|
127
|
+
| Auto router import | 🔜 Planned |
|
|
128
|
+
| Alembic migrations | 🔜 Planned |
|
|
129
|
+
| Docker support | 🔜 Planned |
|
|
130
|
+
| Publish on PyPI | 🎯 Future |
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 🤝 Contributing
|
|
135
|
+
|
|
136
|
+
Pull requests are welcome! 👐
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
⭐ If you like this tool, give the repo a star!
|
|
File without changes
|
fapier-0.1.0/fapi/cli.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from fapi.utils.ustils import render_template, ensure_fastapi_project
|
|
4
|
+
|
|
5
|
+
add = typer.Typer(help="Adds entities like models, schemas, routes...")
|
|
6
|
+
|
|
7
|
+
TEMPLATES_DIR = Path("fapi/templates")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@add.command()
|
|
11
|
+
def route(name: str):
|
|
12
|
+
"""Create a new route file"""
|
|
13
|
+
ensure_fastapi_project()
|
|
14
|
+
if not name:
|
|
15
|
+
typer.echo("You must provide a name for the route")
|
|
16
|
+
raise typer.Exit()
|
|
17
|
+
|
|
18
|
+
project_path = Path(".")
|
|
19
|
+
context = {"name": name.lower(), "class_name": name.capitalize()}
|
|
20
|
+
|
|
21
|
+
routes_dir = project_path / "app/api/routes"
|
|
22
|
+
routes_dir.mkdir(parents=True, exist_ok=True)
|
|
23
|
+
|
|
24
|
+
render_template("app/api/routes/route.py.j2", routes_dir / f"{name.lower()}.py", context)
|
|
25
|
+
|
|
26
|
+
typer.echo(f"✅ Route `{name}` created successfully!")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@add.command()
|
|
30
|
+
def model(
|
|
31
|
+
name: str,
|
|
32
|
+
schema: bool = typer.Option(False, "--schema", help="Add a schema file"),
|
|
33
|
+
crud: bool = typer.Option(False, "--crud", help="Add a CRUD file")
|
|
34
|
+
):
|
|
35
|
+
ensure_fastapi_project()
|
|
36
|
+
if not name:
|
|
37
|
+
typer.echo("You must provide a name for the model")
|
|
38
|
+
raise typer.Exit()
|
|
39
|
+
|
|
40
|
+
project_path = Path(".")
|
|
41
|
+
context = {"name": name.lower(), "class_name": name.capitalize()}
|
|
42
|
+
|
|
43
|
+
models_dir = project_path / "app/models"
|
|
44
|
+
models_dir.mkdir(parents=True, exist_ok=True)
|
|
45
|
+
|
|
46
|
+
render_template("app/models/model.py.j2", models_dir / f"{name.lower()}.py", context)
|
|
47
|
+
|
|
48
|
+
if schema:
|
|
49
|
+
schemas_dir = project_path / "app/schemas"
|
|
50
|
+
schemas_dir.mkdir(parents=True, exist_ok=True)
|
|
51
|
+
|
|
52
|
+
render_template("app/schemas/schema.py.j2", schemas_dir / f"{name.lower()}_schema.py", context)
|
|
53
|
+
typer.echo(f"📦 Schema `{name}` created")
|
|
54
|
+
|
|
55
|
+
if crud:
|
|
56
|
+
crud_dir = project_path / "app/crud"
|
|
57
|
+
crud_dir.mkdir(parents=True, exist_ok=True)
|
|
58
|
+
|
|
59
|
+
render_template("app/crud/crud.py.j2", crud_dir / f"{name.lower()}_crud.py", context)
|
|
60
|
+
typer.echo(f"🛠️ CRUD `{name}` created")
|
|
61
|
+
|
|
62
|
+
typer.echo(f"✅ Model `{name}` created successfully!")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@add.command()
|
|
66
|
+
def service(name: str):
|
|
67
|
+
"""Create a new service file"""
|
|
68
|
+
ensure_fastapi_project()
|
|
69
|
+
|
|
70
|
+
if not name:
|
|
71
|
+
typer.echo("You must provide a name for the service")
|
|
72
|
+
raise typer.Exit()
|
|
73
|
+
|
|
74
|
+
project_path = Path(".")
|
|
75
|
+
context = {"name": name.lower()}
|
|
76
|
+
|
|
77
|
+
routes_dir = project_path / "app/services"
|
|
78
|
+
routes_dir.mkdir(parents=True, exist_ok=True)
|
|
79
|
+
|
|
80
|
+
render_template("app/services/service.py.j2", routes_dir / f"{name.lower()}.py", context)
|
|
81
|
+
|
|
82
|
+
typer.echo(f"✅ service `{name}` created successfully!")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@add.command()
|
|
87
|
+
def crud(name: str):
|
|
88
|
+
"""Create a new crud file"""
|
|
89
|
+
|
|
90
|
+
ensure_fastapi_project()
|
|
91
|
+
|
|
92
|
+
if not name:
|
|
93
|
+
typer.echo("You must provide a name for the service")
|
|
94
|
+
raise typer.Exit()
|
|
95
|
+
|
|
96
|
+
project_path = Path(".")
|
|
97
|
+
context = {"name": name.lower()}
|
|
98
|
+
|
|
99
|
+
routes_dir = project_path / "app/crud"
|
|
100
|
+
routes_dir.mkdir(parents=True, exist_ok=True)
|
|
101
|
+
|
|
102
|
+
render_template("app/crud/crud.py.j2", routes_dir / f"{name.lower()}.py", context)
|
|
103
|
+
|
|
104
|
+
typer.echo(f"✅ crud `{name}` created successfully!")
|
|
105
|
+
|
|
106
|
+
@add.command()
|
|
107
|
+
def schema(name: str):
|
|
108
|
+
"""Create a new schema file"""
|
|
109
|
+
|
|
110
|
+
ensure_fastapi_project()
|
|
111
|
+
|
|
112
|
+
if not name:
|
|
113
|
+
typer.echo("You must provide a name for the service")
|
|
114
|
+
raise typer.Exit()
|
|
115
|
+
|
|
116
|
+
project_path = Path(".")
|
|
117
|
+
context = {"name": name.lower(), "class_name": name.capitalize()}
|
|
118
|
+
|
|
119
|
+
routes_dir = project_path / "app/schemas"
|
|
120
|
+
routes_dir.mkdir(parents=True, exist_ok=True)
|
|
121
|
+
|
|
122
|
+
render_template("app/schemas/schema.py.j2", routes_dir / f"{name.lower()}.py", context)
|
|
123
|
+
|
|
124
|
+
typer.echo(f"✅ schema `{name}` created successfully!")
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
from fapi.utils.ustils import render_template, req_installer, create_venv
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
create_app = typer.Typer(help="FastAPI project generator")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@create_app.command()
|
|
8
|
+
def create(
|
|
9
|
+
project_name: str = typer.Argument(...),
|
|
10
|
+
db: str = typer.Option(
|
|
11
|
+
None, "--db", help="Database: sqlite or postgres", case_sensitive=False
|
|
12
|
+
),
|
|
13
|
+
routes: bool = typer.Option(
|
|
14
|
+
None, "--routes", help="Generate routes?"
|
|
15
|
+
),
|
|
16
|
+
):
|
|
17
|
+
"""Create a new FastAPI project"""
|
|
18
|
+
project_dir = Path(project_name)
|
|
19
|
+
|
|
20
|
+
if project_dir.exists():
|
|
21
|
+
typer.echo(f"Directory {project_name} already exists!")
|
|
22
|
+
raise typer.Exit()
|
|
23
|
+
|
|
24
|
+
typer.echo(f"Creating FastAPI project: {project_name}... ✅")
|
|
25
|
+
if db is None:
|
|
26
|
+
use_db = typer.confirm("do you want to use a db?")
|
|
27
|
+
db_choice = typer.prompt("Choose a Database (sqlite/postgres)", default="sqlite") if use_db else None
|
|
28
|
+
else:
|
|
29
|
+
use_db = db.lower() in ["postgres", "sqlite"]
|
|
30
|
+
db_choice = db.lower()
|
|
31
|
+
if not use_db:
|
|
32
|
+
typer.echo(f"Invalid DB option! {db} neither 'sqlite' not 'postgres")
|
|
33
|
+
raise typer.Exit()
|
|
34
|
+
|
|
35
|
+
if routes is None:
|
|
36
|
+
use_routes = typer.confirm("do you want to generate routes?")
|
|
37
|
+
else:
|
|
38
|
+
use_routes = routes
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
context = {"project_name": project_name, "use_db":use_db, "db_choice": db_choice, "use_routes": use_routes}
|
|
43
|
+
|
|
44
|
+
# Create folders
|
|
45
|
+
(project_dir / "app").mkdir(parents=True, exist_ok=True)
|
|
46
|
+
|
|
47
|
+
# Render templates
|
|
48
|
+
render_template("app/main.py.j2", project_dir / "app/main.py", context)
|
|
49
|
+
(project_dir / "app" / "core").mkdir()
|
|
50
|
+
render_template("app/core/config.py.j2", project_dir / "app/core/config.py", context)
|
|
51
|
+
if use_db:
|
|
52
|
+
(project_dir / "app" / "models").mkdir()
|
|
53
|
+
(project_dir / "app" / "schemas").mkdir()
|
|
54
|
+
(project_dir / "app" / "crud").mkdir()
|
|
55
|
+
render_template("app/crud/user.py.j2", project_dir / "app/crud/user.py", context)
|
|
56
|
+
render_template("app/core/database.py.j2", project_dir / "app/core/database.py", context)
|
|
57
|
+
render_template("app/models/user.py.j2", project_dir / "app/models/user.py", context)
|
|
58
|
+
render_template("app/schemas/user.py.j2", project_dir / "app/schemas/user.py", context)
|
|
59
|
+
if use_routes:
|
|
60
|
+
(project_dir / "app" / "api").mkdir()
|
|
61
|
+
(project_dir / "app" / "services").mkdir()
|
|
62
|
+
(project_dir / "app" / "api" / "routes").mkdir()
|
|
63
|
+
render_template("app/api/routes/user.py.j2", project_dir / "app/api/routes/user.py", context)
|
|
64
|
+
render_template("app/api/router.py.j2", project_dir / "app/api/router.py", context)
|
|
65
|
+
render_template("app/services/passwordHash.py.j2", project_dir / "app/services/passwordHash.py", context)
|
|
66
|
+
render_template("requirements.txt.j2", project_dir / "requirements.txt", context)
|
|
67
|
+
render_template("app/__init__.py.j2", project_dir / "app/__init__.py", context)
|
|
68
|
+
# Create .env example
|
|
69
|
+
(project_dir / ".env").write_text("APP_NAME=" + project_name)
|
|
70
|
+
create_venv(project_dir)
|
|
71
|
+
req_installer(project_dir)
|
|
72
|
+
(project_dir / ".fastapi").write_text("fastapi-project")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
typer.echo("✅ Project created successfully!")
|
|
76
|
+
typer.echo(f"Next steps 👉 \n")
|
|
77
|
+
typer.echo(f"cd {project_name}")
|
|
78
|
+
typer.echo("""activate venv:
|
|
79
|
+
linux / mac: source .venv/bin/activate
|
|
80
|
+
Windows (PowerShell):
|
|
81
|
+
.venv\\Scripts\\Activate.ps1
|
|
82
|
+
|
|
83
|
+
Windows (CMD):
|
|
84
|
+
.venv\\Scripts\\activate.bat
|
|
85
|
+
""")
|
|
86
|
+
typer.echo(f"uvicorn app.main:app --reload")
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from jinja2 import Environment, FileSystemLoader
|
|
4
|
+
import subprocess
|
|
5
|
+
from fapi.constants import TEMPLATES_DIR
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def create_venv(project_dir: Path):
|
|
9
|
+
typer.echo("🛠 Creating virtual environment...")
|
|
10
|
+
subprocess.run(["python3", "-m", "venv", ".venv"], cwd=project_dir)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def req_installer(project_dir: Path):
|
|
14
|
+
req_file = project_dir / "requirements.txt"
|
|
15
|
+
pip_path = project_dir / ".venv" / "bin" / "pip"
|
|
16
|
+
|
|
17
|
+
typer.echo("📦 Installing dependencies...")
|
|
18
|
+
subprocess.run([str(pip_path), "install", "-r", str(req_file)])
|
|
19
|
+
|
|
20
|
+
def render_template(src, dest, context):
|
|
21
|
+
env = Environment(loader=FileSystemLoader(TEMPLATES_DIR))
|
|
22
|
+
template = env.get_template(src)
|
|
23
|
+
rendered = template.render(**context)
|
|
24
|
+
|
|
25
|
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
26
|
+
dest.write_text(rendered)
|
|
27
|
+
|
|
28
|
+
def ensure_fastapi_project():
|
|
29
|
+
if not Path(".fastapi").exists():
|
|
30
|
+
typer.echo("❌ This is not a FastAPI project generated by this CLI.")
|
|
31
|
+
typer.echo("Hint: Run `fapi create <project-name>` first.")
|
|
32
|
+
raise typer.Exit(1)
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fapier
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A command-line tool to scaffold and bootstrap FastAPI projects quickly.
|
|
5
|
+
Author: Dahmoun Mouaine Aymen
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/aymen-dahmoun/fapi
|
|
8
|
+
Project-URL: Repository, https://github.com/aymen-dahmoun/fapi
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: fastapi
|
|
12
|
+
Requires-Dist: uvicorn[standard]
|
|
13
|
+
Requires-Dist: typer[all]
|
|
14
|
+
Requires-Dist: jinja2
|
|
15
|
+
Requires-Dist: sqlalchemy
|
|
16
|
+
Requires-Dist: passlib[bcrypt]
|
|
17
|
+
Requires-Dist: pydantic[email]
|
|
18
|
+
Requires-Dist: python-dotenv
|
|
19
|
+
Requires-Dist: pydantic-settings
|
|
20
|
+
|
|
21
|
+
# FastAPI Project Generator CLI
|
|
22
|
+
|
|
23
|
+
A CLI tool that scaffolds FastAPI projects with optional database and API structure.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## ✅ Features
|
|
28
|
+
|
|
29
|
+
| Feature | Description |
|
|
30
|
+
| -------------------------- | ----------------------------------------------- |
|
|
31
|
+
| Generate FastAPI project | Creates a full FastAPI folder structure |
|
|
32
|
+
| Optional Database | Create project with or without SQLAlchemy setup |
|
|
33
|
+
| Auto-creates virtualenv | Creates `.venv` inside the project |
|
|
34
|
+
| Auto-installs requirements | Installs dependencies based on options |
|
|
35
|
+
| Jinja2 Templates | Clean and flexible template system |
|
|
36
|
+
| Developer friendly | Simple prompts & automatic setup |
|
|
37
|
+
| CLI `add` commands | Add routes, models, schemas, crud, services |
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 📂 Project Output Structure
|
|
42
|
+
|
|
43
|
+
When DB and routes are enabled:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
project_name/
|
|
47
|
+
├─ app/
|
|
48
|
+
│ ├─ main.py
|
|
49
|
+
│ ├─ core/
|
|
50
|
+
│ │ └─ config.py
|
|
51
|
+
│ ├─ models/
|
|
52
|
+
│ │ └─ user.py
|
|
53
|
+
│ ├─ schemas/
|
|
54
|
+
│ │ └─ user.py
|
|
55
|
+
│ ├─ crud/
|
|
56
|
+
│ │ └─ user.py
|
|
57
|
+
│ ├─ services/
|
|
58
|
+
│ │ └─ example.py
|
|
59
|
+
│ ├─ api/
|
|
60
|
+
│ │ └─ router.py
|
|
61
|
+
│ └─ __init__.py
|
|
62
|
+
├─ .fastapi # internal flag to detect project
|
|
63
|
+
├─ .env
|
|
64
|
+
├─ requirements.txt
|
|
65
|
+
└─ .venv/
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
If database or routes are disabled, the tool skips those folders.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 🧰 Installation
|
|
73
|
+
|
|
74
|
+
### Clone Repo
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
git clone https://github.com/aymen-Dahmoun/FApi.git
|
|
78
|
+
cd FApi
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Install dependencies
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install -r requirements.txt
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
> Requires Python 3.10+
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 🚀 Usage
|
|
92
|
+
|
|
93
|
+
### Create a project
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
python cli.py myproject
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Answer prompts
|
|
100
|
+
|
|
101
|
+
Example interaction:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
Do you want to use a DB? [y/n]: y
|
|
105
|
+
Choose a Database (sqlite/postgres) [sqlite]: sqlite
|
|
106
|
+
Do you want to generate routes? [y/n]: y
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
or simply run
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
python cli.py myproject --db sqlite --routes
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Add new components
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
fapi add route product
|
|
119
|
+
fapi add model product --schema --crud
|
|
120
|
+
fapi add service payment
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
> Auto-detects if you're inside a FastAPI project using `.fastapi`
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 🏁 Run the project
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
cd myproject
|
|
131
|
+
source .venv/bin/activate # Linux/Mac
|
|
132
|
+
# or .venv\Scripts\activate on Windows
|
|
133
|
+
|
|
134
|
+
uvicorn app.main:app --reload
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## 📌 Roadmap
|
|
140
|
+
|
|
141
|
+
| Feature | Status |
|
|
142
|
+
| ---------------------- | ---------- |
|
|
143
|
+
| Basic FastAPI scaffold | ✅ Done |
|
|
144
|
+
| Optional DB | ✅ Done |
|
|
145
|
+
| Optional API | ✅ Done |
|
|
146
|
+
| `fapi add` commands | ✅ Done |
|
|
147
|
+
| Auto router import | 🔜 Planned |
|
|
148
|
+
| Alembic migrations | 🔜 Planned |
|
|
149
|
+
| Docker support | 🔜 Planned |
|
|
150
|
+
| Publish on PyPI | 🎯 Future |
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## 🤝 Contributing
|
|
155
|
+
|
|
156
|
+
Pull requests are welcome! 👐
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
⭐ If you like this tool, give the repo a star!
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
fapi/__init__.py
|
|
4
|
+
fapi/cli.py
|
|
5
|
+
fapi/constants.py
|
|
6
|
+
fapi/commands/__init__.py
|
|
7
|
+
fapi/commands/add.py
|
|
8
|
+
fapi/commands/create.py
|
|
9
|
+
fapi/utils/__init__.py
|
|
10
|
+
fapi/utils/ustils.py
|
|
11
|
+
fapier.egg-info/PKG-INFO
|
|
12
|
+
fapier.egg-info/SOURCES.txt
|
|
13
|
+
fapier.egg-info/dependency_links.txt
|
|
14
|
+
fapier.egg-info/entry_points.txt
|
|
15
|
+
fapier.egg-info/requires.txt
|
|
16
|
+
fapier.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fapi
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fapier"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A command-line tool to scaffold and bootstrap FastAPI projects quickly."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Dahmoun Mouaine Aymen" }
|
|
12
|
+
]
|
|
13
|
+
license = { text = "MIT" }
|
|
14
|
+
requires-python = ">=3.10"
|
|
15
|
+
|
|
16
|
+
dependencies = [
|
|
17
|
+
"fastapi",
|
|
18
|
+
"uvicorn[standard]",
|
|
19
|
+
"typer[all]",
|
|
20
|
+
"jinja2",
|
|
21
|
+
"sqlalchemy",
|
|
22
|
+
"passlib[bcrypt]",
|
|
23
|
+
"pydantic[email]",
|
|
24
|
+
"python-dotenv",
|
|
25
|
+
"pydantic-settings"
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/aymen-dahmoun/fapi"
|
|
30
|
+
Repository = "https://github.com/aymen-dahmoun/fapi"
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
fapi = "fapi.cli:app"
|
fapier-0.1.0/setup.cfg
ADDED