Generador de Backends a partir de YAML
Project description
YAML-to-Backend
Una librería Python para generar backends completos a partir de definiciones YAML.
Descripción
YAML-to-Backend es una herramienta que permite generar automáticamente backends completos con FastAPI, SQLAlchemy y SQLModel a partir de archivos YAML que definen entidades, campos, relaciones y permisos.
Características
- Generación automática de modelos: Crea modelos SQLModel y Pydantic automáticamente
- CRUD automático: Genera endpoints CRUD completos para cada entidad
- Autenticación integrada: Sistema de autenticación JWT incluido
- Validación automática: Validación de datos basada en las definiciones YAML
- Documentación automática: Swagger/OpenAPI generado automáticamente
- Soporte para relaciones: Claves foráneas y relaciones entre entidades
- Sistema de permisos: Control de acceso basado en roles
Instalación
pip install yaml-to-backend
Uso
1. Definir entidades en YAML
Crea archivos YAML que definan tus entidades:
# entidades/usuario.yaml
entidad: Usuario
tabla: usuarios
descripcion: Gestión de usuarios del sistema
campos:
id:
tipo: integer
pk: true
nombre:
tipo: string
max: 100
required: true
email:
tipo: string
max: 255
required: true
ejemplo: "usuario@ejemplo.com"
password:
tipo: string
max: 255
required: true
activo:
tipo: boolean
required: true
ejemplo: true
rol_id:
tipo: integer
fk: roles.id
required: true
permisos:
admin: [r, w, d]
usuario:
yo:
campo_usuario: id
2. Usar la librería
from yaml_to_backend import update_config, get_run_backend
# Configurar la base de datos
update_config(
DB_HOST='localhost',
DB_USER='usuario',
DB_PASSWORD='password',
DB_NAME='mi_base_datos',
DB_PORT=3306,
PORT=8000
)
# Ejecutar el backend
run_backend = get_run_backend()
run_backend()
3. Usar desde línea de comandos
# Configurar y ejecutar
yaml-to-backend --config entidades/ --port 8000
# Solo validar YAML
yaml-to-backend --validate entidades/
Estructura del Proyecto
yaml-to-backend/
├── yaml_to_backend/ # Código fuente de la librería
│ ├── __init__.py
│ ├── app.py # Aplicación principal
│ ├── config.py # Configuración
│ ├── cli.py # Interfaz de línea de comandos
│ ├── api/ # Generadores de API
│ ├── core/ # Lógica principal
│ ├── db/ # Modelos de base de datos
│ └── security/ # Autenticación y seguridad
├── tests/ # Pruebas unitarias
├── setup.py # Configuración de instalación
├── pyproject.toml # Configuración moderna del proyecto
├── MANIFEST.in # Archivos a incluir en el paquete
└── README.md # Este archivo
Tipos de Datos Soportados
integer: Números enterosstring: Cadenas de textoboolean: Valores booleanosdatetime: Fechas y horasdate: Solo fechastime: Solo horasfloat: Números decimalestext: Texto largojson: Datos JSON
Configuración
Variables de Entorno
DB_HOST: Host de la base de datosDB_USER: Usuario de la base de datosDB_PASSWORD: Contraseña de la base de datosDB_NAME: Nombre de la base de datosDB_PORT: Puerto de la base de datosPORT: Puerto del servidor webSECRET_KEY: Clave secreta para JWTALGORITHM: Algoritmo de encriptación JWT
Configuración Programática
from yaml_to_backend import update_config
update_config(
DB_HOST='localhost',
DB_USER='usuario',
DB_PASSWORD='password',
DB_NAME='mi_db',
DB_PORT=3306,
PORT=8000,
SECRET_KEY='mi_clave_secreta',
ALGORITHM='HS256'
)
Desarrollo
Instalación para desarrollo
git clone https://github.com/cxmjg/yaml-to-backend.git
cd yaml-to-backend
python -m venv .venv
source .venv/bin/activate # En Windows: .venv\Scripts\activate
pip install -e .
Ejecutar pruebas
pytest
Construir el paquete
python -m build
Publicación Automática
Este proyecto utiliza GitHub Actions con Trusted Publishers para publicar automáticamente en PyPI cuando se hace push a la rama main.
Configuración de Trusted Publishers
- Ve a tu proyecto en PyPI
- En "Settings" > "Trusted publishers"
- Agrega un nuevo publisher con:
- Owner:
cxmjg - Repository name:
yaml-to-backend - Workflow name:
publish - Environment name: (dejar vacío)
- Owner:
Licencia
MIT License - ver LICENSE para más detalles.
Contribuir
- Fork el proyecto
- Crea una rama para tu feature (
git checkout -b feature/AmazingFeature) - Commit tus cambios (
git commit -m 'Add some AmazingFeature') - Push a la rama (
git push origin feature/AmazingFeature) - Abre un Pull Request
Changelog
v0.1.0
- Primera versión estable
- Generación automática de modelos y CRUD
- Sistema de autenticación JWT
- Soporte para relaciones entre entidades
- CLI para configuración y validación
- Publicación automática con GitHub Actions
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yaml_to_backend-0.1.8.tar.gz.
File metadata
- Download URL: yaml_to_backend-0.1.8.tar.gz
- Upload date:
- Size: 23.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b1f2951994134d55854c2aebc5e1eda9eccfbce2f59bad3e7f791b0ebfc1779
|
|
| MD5 |
a7af434dfce84c03a4432054625ea37a
|
|
| BLAKE2b-256 |
cb47bf2b9a370a08e9613b86d981a44c70ec6f26f724b0fa61c4de560f559ccb
|
Provenance
The following attestation bundles were made for yaml_to_backend-0.1.8.tar.gz:
Publisher:
publish.yml on cxmjg/yaml-to-backend
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yaml_to_backend-0.1.8.tar.gz -
Subject digest:
4b1f2951994134d55854c2aebc5e1eda9eccfbce2f59bad3e7f791b0ebfc1779 - Sigstore transparency entry: 332676617
- Sigstore integration time:
-
Permalink:
cxmjg/yaml-to-backend@ab2e58a2f2fc6c00784aaa8d41fda233c9399562 -
Branch / Tag:
refs/tags/v0.1.8 - Owner: https://github.com/cxmjg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ab2e58a2f2fc6c00784aaa8d41fda233c9399562 -
Trigger Event:
release
-
Statement type:
File details
Details for the file yaml_to_backend-0.1.8-py3-none-any.whl.
File metadata
- Download URL: yaml_to_backend-0.1.8-py3-none-any.whl
- Upload date:
- Size: 25.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d092572f9aa7ae29b0ed66f798671f496e7ca12a16e019e605f5c41a67d84706
|
|
| MD5 |
15bd115a2bd67971f4931c74254dd42c
|
|
| BLAKE2b-256 |
5f480341ed0c21e5a5b962b26245d0c3cd6f9bf7662c35007b94c0f248e355d6
|
Provenance
The following attestation bundles were made for yaml_to_backend-0.1.8-py3-none-any.whl:
Publisher:
publish.yml on cxmjg/yaml-to-backend
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yaml_to_backend-0.1.8-py3-none-any.whl -
Subject digest:
d092572f9aa7ae29b0ed66f798671f496e7ca12a16e019e605f5c41a67d84706 - Sigstore transparency entry: 332676644
- Sigstore integration time:
-
Permalink:
cxmjg/yaml-to-backend@ab2e58a2f2fc6c00784aaa8d41fda233c9399562 -
Branch / Tag:
refs/tags/v0.1.8 - Owner: https://github.com/cxmjg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ab2e58a2f2fc6c00784aaa8d41fda233c9399562 -
Trigger Event:
release
-
Statement type: