fastapi-mike 0.0.0__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.
- fastapi_mike-0.0.0.dist-info/METADATA +141 -0
- fastapi_mike-0.0.0.dist-info/RECORD +11 -0
- fastapi_mike-0.0.0.dist-info/WHEEL +5 -0
- fastapi_mike-0.0.0.dist-info/entry_points.txt +2 -0
- fastapi_mike-0.0.0.dist-info/licenses/LICENSE +22 -0
- fastapi_mike-0.0.0.dist-info/top_level.txt +1 -0
- fastmike/__init__.py +0 -0
- fastmike/__main__.py +5 -0
- fastmike/cli.py +94 -0
- fastmike/templates.py +41 -0
- fastmike/utils.py +25 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastapi-mike
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: FastAPI Enterprise Scaffolder by MIKECARDONA076
|
|
5
|
+
Author-email: Mike Cardona <mikecardona076@gmail.com.com>
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: click>=8.0.0
|
|
10
|
+
Requires-Dist: sqlalchemy>=2.0.0
|
|
11
|
+
Requires-Dist: alembic>=1.10.0
|
|
12
|
+
Requires-Dist: requests>=2.28.0
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# 🚀 FastMike – FastAPI Enterprise Scaffolder
|
|
16
|
+
|
|
17
|
+
**FastMike** es una herramienta de línea de comandos (**CLI**) de alto rendimiento diseñada para **automatizar la creación de proyectos FastAPI** siguiendo estándares **empresariales** y principios de **Clean Architecture**.
|
|
18
|
+
|
|
19
|
+
Desarrollado y mantenido por **MIKECARDONA076**.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## ✨ Características Principales
|
|
24
|
+
|
|
25
|
+
- **Estructura Profesional**
|
|
26
|
+
Genera automáticamente un layout modular:
|
|
27
|
+
- `api`
|
|
28
|
+
- `core`
|
|
29
|
+
- `crud`
|
|
30
|
+
- `models`
|
|
31
|
+
- `schemas`
|
|
32
|
+
- `services`
|
|
33
|
+
|
|
34
|
+
- **Alembic Ready**
|
|
35
|
+
Configuración automática de migraciones de base de datos con **detección de modelos**.
|
|
36
|
+
|
|
37
|
+
- **Suite TESTMIKE**
|
|
38
|
+
Incluye **5 pruebas rápidas de humo** para validar:
|
|
39
|
+
- Base de Datos
|
|
40
|
+
- CORS
|
|
41
|
+
- Seguridad
|
|
42
|
+
- Integridad de Modelos
|
|
43
|
+
- Respaldo de archivos
|
|
44
|
+
|
|
45
|
+
- **Docker Support**
|
|
46
|
+
Genera:
|
|
47
|
+
- `Dockerfile`
|
|
48
|
+
- `docker-compose.yml`
|
|
49
|
+
Listo para despliegues rápidos.
|
|
50
|
+
|
|
51
|
+
- **Seguridad Integrada**
|
|
52
|
+
Configuración base de:
|
|
53
|
+
- Middlewares de CORS
|
|
54
|
+
- Utilidades de hashing y criptografía
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 🛠️ Instalación
|
|
59
|
+
|
|
60
|
+
Instala el paquete de forma global o dentro de un entorno virtual:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install fastmike
|
|
64
|
+
````
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## 🚀 Uso Rápido
|
|
69
|
+
|
|
70
|
+
Para desplegar la estructura base de tu nueva API:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
fastmike init --name mi-proyecto-pro
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## 🆘 ¿El comando `fastmike` no se reconoce?
|
|
79
|
+
|
|
80
|
+
Si el comando no está disponible por variables de entorno (`PATH`), usa el modo módulo de Python:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
python -m fastmike init --name mi-proyecto-pro
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Este método es **infalible**.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## 📁 Estructura Generada
|
|
91
|
+
|
|
92
|
+
Al ejecutar el comando, se creará el siguiente árbol de directorios:
|
|
93
|
+
|
|
94
|
+
```text
|
|
95
|
+
nombre-de-tu-proyecto/
|
|
96
|
+
├── app/
|
|
97
|
+
│ ├── api/v1/ # Endpoints versionados
|
|
98
|
+
│ ├── core/ # Configuración y Seguridad
|
|
99
|
+
│ ├── crud/ # Lógica atómica de DB
|
|
100
|
+
│ ├── models/ # Modelos SQLAlchemy
|
|
101
|
+
│ ├── schemas/ # DTOs de Pydantic
|
|
102
|
+
│ ├── services/ # Lógica de negocio compleja
|
|
103
|
+
│ └── main.py # Punto de entrada
|
|
104
|
+
├── TESTMIKE/ # Suite de validación rápida
|
|
105
|
+
├── alembic/ # Migraciones de DB
|
|
106
|
+
├── .env # Variables de entorno
|
|
107
|
+
├── Dockerfile # Configuración Docker
|
|
108
|
+
└── requirements.txt # Dependencias base
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 🧪 Validando tu Proyecto (TESTMIKE)
|
|
114
|
+
|
|
115
|
+
Una vez creada la estructura, entra a la carpeta del proyecto y ejecuta los tests de validación rápida:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# Validar conexión a Base de Datos
|
|
119
|
+
python TESTMIKE/db_check.py
|
|
120
|
+
|
|
121
|
+
# Validar integridad de modelos
|
|
122
|
+
python TESTMIKE/model_integrity.py
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Estos tests confirman que el proyecto está **correctamente configurado antes de desarrollar**.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 🤝 Contribuciones y Soporte
|
|
130
|
+
|
|
131
|
+
Si encuentras errores o tienes sugerencias:
|
|
132
|
+
|
|
133
|
+
1. Haz un **Fork** del proyecto
|
|
134
|
+
2. Crea una rama para tu mejora:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
git checkout -b feature/Mejora
|
|
138
|
+
```
|
|
139
|
+
3. Envía un **Pull Request**
|
|
140
|
+
|
|
141
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
fastapi_mike-0.0.0.dist-info/licenses/LICENSE,sha256=wioVC01h0BZaoURb49RXMpk8f309BxHdvq-ibdgf_1s,502
|
|
2
|
+
fastmike/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
fastmike/__main__.py,sha256=fcOdMNlBtIL1PMXJGw3LIL0T6WHguQ5yP5V7xs1rSHU,121
|
|
4
|
+
fastmike/cli.py,sha256=RLsWX3-ZikEqc5apbMeWXBT2m9YZ9L1ux1_nUpyzcmM,3358
|
|
5
|
+
fastmike/templates.py,sha256=JLuvdSTXmYZw7T9gTW5Sie-nGZ8GgdnSBl3JhM4D3bE,1231
|
|
6
|
+
fastmike/utils.py,sha256=MPA0uMFMNWiKoNTYoIG_eWBrM3k4MJRmIZitfmFDGFg,1117
|
|
7
|
+
fastapi_mike-0.0.0.dist-info/METADATA,sha256=SJ3AjSaTghjxws0gBBvDrzw1RNiTjmNLB1QDVdbd7qw,3554
|
|
8
|
+
fastapi_mike-0.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
fastapi_mike-0.0.0.dist-info/entry_points.txt,sha256=PQhW7CNBRYcGSOBFdnOUY8A1lbsggX8Lzmxep19SBPo,51
|
|
10
|
+
fastapi_mike-0.0.0.dist-info/top_level.txt,sha256=4IZpMJzbvfpIPmSBvjD6S0KG4eL7DqQ74NVJBDO9bjo,9
|
|
11
|
+
fastapi_mike-0.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fastmike"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Mike Cardona", email="mikcardona076@gmail.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "FastAPI Enterprise Scaffolder by MIKECARDONA076"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
dependencies = [
|
|
15
|
+
"click>=8.0.0",
|
|
16
|
+
"sqlalchemy>=2.0.0",
|
|
17
|
+
"alembic>=1.10.0",
|
|
18
|
+
"requests>=2.28.0",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
fastmike = "fastmike.cli:main"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fastmike
|
fastmike/__init__.py
ADDED
|
File without changes
|
fastmike/__main__.py
ADDED
fastmike/cli.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import click
|
|
2
|
+
import os
|
|
3
|
+
import pathlib
|
|
4
|
+
import subprocess
|
|
5
|
+
from .utils import print_banner, get_db_url
|
|
6
|
+
from .templates import (
|
|
7
|
+
get_main_py,
|
|
8
|
+
get_db_base,
|
|
9
|
+
get_api_router,
|
|
10
|
+
get_testmike_files,
|
|
11
|
+
get_alembic_env_py
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
@click.group()
|
|
15
|
+
def main():
|
|
16
|
+
"""CLI Profesional de fastapi-mike por MIKECARDONA076"""
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
@main.command()
|
|
20
|
+
@click.option('--name', default='fastapi-mike-api', help='Nombre del proyecto')
|
|
21
|
+
def init(name):
|
|
22
|
+
"""Inicializa la estructura perfecta de FastAPI"""
|
|
23
|
+
print_banner()
|
|
24
|
+
click.secho(f"🚀 Creando proyecto: {name}...", fg="yellow")
|
|
25
|
+
# Lógica de creación de carpetas y archivos...
|
|
26
|
+
click.secho("✅ ¡Listo! Proyecto configurado.", fg="green", bold=True)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@main.command()
|
|
30
|
+
@click.option('--name', default='fastapi-project', help='Nombre del proyecto')
|
|
31
|
+
def init(name):
|
|
32
|
+
"""Inicializa un nuevo proyecto con la estructura profesional de Mike."""
|
|
33
|
+
print_banner()
|
|
34
|
+
|
|
35
|
+
# 1. Crear Estructura de Carpetas
|
|
36
|
+
folders = [
|
|
37
|
+
"app/api/v1/endpoints", "app/core", "app/crud", "app/db",
|
|
38
|
+
"app/models", "app/schemas", "app/services", "app/admin",
|
|
39
|
+
"tests/api", "tests/crud", "TESTMIKE"
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
click.echo("📁 Creando estructura de directorios...")
|
|
43
|
+
for folder in folders:
|
|
44
|
+
path = pathlib.Path(folder)
|
|
45
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
46
|
+
(path / "__init__.py").touch()
|
|
47
|
+
|
|
48
|
+
# 2. Obtener URL de DB y Generar Archivos Base
|
|
49
|
+
db_url = get_db_url()
|
|
50
|
+
|
|
51
|
+
click.echo("📝 Generando archivos base...")
|
|
52
|
+
with open("app/main.py", "w", encoding="utf-8") as f:
|
|
53
|
+
f.write(get_main_py(name))
|
|
54
|
+
|
|
55
|
+
with open("app/db/base_class.py", "w", encoding="utf-8") as f:
|
|
56
|
+
f.write(get_db_base())
|
|
57
|
+
|
|
58
|
+
with open("app/api/v1/api.py", "w", encoding="utf-8") as f:
|
|
59
|
+
f.write(get_api_router())
|
|
60
|
+
|
|
61
|
+
# 3. Generar Suite TESTMIKE
|
|
62
|
+
click.echo("🧪 Generando suite de pruebas rápidas TESTMIKE...")
|
|
63
|
+
tests = get_testmike_files(db_url)
|
|
64
|
+
for filename, content in tests.items():
|
|
65
|
+
with open(f"TESTMIKE/{filename}", "w", encoding="utf-8") as f:
|
|
66
|
+
f.write(content)
|
|
67
|
+
|
|
68
|
+
# 4. Configurar Alembic
|
|
69
|
+
click.echo("⚙️ Configurando Alembic...")
|
|
70
|
+
try:
|
|
71
|
+
if not os.path.exists("alembic.ini"):
|
|
72
|
+
subprocess.run(["alembic", "init", "alembic"], capture_output=True)
|
|
73
|
+
|
|
74
|
+
# Modificar alembic.ini
|
|
75
|
+
with open("alembic.ini", "r") as f: lines = f.readlines()
|
|
76
|
+
with open("alembic.ini", "w") as f:
|
|
77
|
+
for line in lines:
|
|
78
|
+
if line.startswith("sqlalchemy.url"):
|
|
79
|
+
f.write(f"sqlalchemy.url = {db_url}\n")
|
|
80
|
+
else: f.write(line)
|
|
81
|
+
|
|
82
|
+
# Sobreescribir env.py para auto-detección
|
|
83
|
+
with open("alembic/env.py", "w", encoding="utf-8") as f:
|
|
84
|
+
f.write(get_alembic_env_py())
|
|
85
|
+
|
|
86
|
+
except Exception as e:
|
|
87
|
+
click.secho(f"⚠️ Error configurando Alembic: {e}", fg="yellow")
|
|
88
|
+
|
|
89
|
+
# 5. Extras (Docker & .env)
|
|
90
|
+
with open(".env", "w") as f:
|
|
91
|
+
f.write(f"PROJECT_NAME={name}\nDATABASE_URL={db_url}\n")
|
|
92
|
+
|
|
93
|
+
click.secho(f"\n🚀 Proyecto '{name}' listo para despegar!", fg='green', bold=True)
|
|
94
|
+
click.echo("Usa 'pip install -r requirements.txt' y luego 'uvicorn app.main:app --reload'")
|
fastmike/templates.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
def get_main_py(project_name):
|
|
2
|
+
return f"""from fastapi import FastAPI
|
|
3
|
+
from app.api.v1.api import api_router
|
|
4
|
+
|
|
5
|
+
app = FastAPI(title="{project_name}")
|
|
6
|
+
app.include_router(api_router, prefix="/api/v1")
|
|
7
|
+
|
|
8
|
+
@app.get("/")
|
|
9
|
+
def read_root():
|
|
10
|
+
return {{"message": "Welcome to {project_name}", "mike": "cardona076"}}
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def get_api_router():
|
|
14
|
+
return "from fastapi import APIRouter\napi_router = APIRouter()"
|
|
15
|
+
|
|
16
|
+
def get_db_base():
|
|
17
|
+
return """from sqlalchemy.ext.declarative import as_declarative, declared_attr
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
@as_declarative()
|
|
21
|
+
class Base:
|
|
22
|
+
id: Any
|
|
23
|
+
__name__: str
|
|
24
|
+
@declared_attr
|
|
25
|
+
def __tablename__(cls) -> str:
|
|
26
|
+
return cls.__name__.lower()
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def get_testmike_files(db_url):
|
|
30
|
+
return {
|
|
31
|
+
"db_check.py": f"import sqlalchemy; print('Checking {db_url}')",
|
|
32
|
+
"security_auth.py": "import secrets; print(f'Token: {secrets.token_urlsafe(32)}')",
|
|
33
|
+
# ... (puedes añadir los otros 3 aquí siguiendo el mismo formato)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
def get_alembic_env_py():
|
|
37
|
+
return """# Contenido de env.py para detección automática de modelos
|
|
38
|
+
from app.db.base_class import Base
|
|
39
|
+
target_metadata = Base.metadata
|
|
40
|
+
# ... (resto de la lógica de alembic)
|
|
41
|
+
"""
|
fastmike/utils.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
def print_banner():
|
|
4
|
+
banner = r"""
|
|
5
|
+
__ __ _____ _ cache _____ _____ _____ _____ ____ _ _
|
|
6
|
+
| \/ |_ _| |/ / | ____| | ___|/\ / \ / ____|/ ____| / __ \| \ | |
|
|
7
|
+
| \ / | | | | ' / | _| | |_ / \ / \| (___ | | | | | | \| |
|
|
8
|
+
| |\/| | | | | < | |___ | _|/ /\ \\ / / \___ \| | | | | | . ` |
|
|
9
|
+
| | | |_| |_| . \ | |____ | | / ____ \/ / ____) | |____ | |__| | |\ |
|
|
10
|
+
|_| |_|_____|_|\_\ |______||_|/_/ \_\/ |_____/ \_____| \____/|_| \_|
|
|
11
|
+
|
|
12
|
+
DEVELOPED BY: MIKECARDONA076
|
|
13
|
+
"""
|
|
14
|
+
click.secho(banner, fg="cyan")
|
|
15
|
+
|
|
16
|
+
def get_db_url():
|
|
17
|
+
click.echo("\nConfiguración de Base de Datos:")
|
|
18
|
+
db_type = click.prompt(
|
|
19
|
+
"Elige DB (1: SQLite, 2: Postgres, 3: MySQL)",
|
|
20
|
+
type=click.Choice(['1', '2', '3']),
|
|
21
|
+
default='1'
|
|
22
|
+
)
|
|
23
|
+
if db_type == '1': return "sqlite:///./sql_app.db"
|
|
24
|
+
if db_type == '2': return "postgresql://user:pass@localhost:5432/db"
|
|
25
|
+
return "mysql+pymysql://user:pass@localhost:3306/db"
|