Plantilla de proyecto·Pro
Acortador de enlaces con FastAPI
Un acortador de enlaces en Python con FastAPI y SQLite. Crea códigos cortos, redirige y cuenta los clics, y trae un formulario de una página y tests con pytest. Necesita Python 3.10 o posterior con pip en el entorno Linux; instala 14 paquetes con versión fijada.
Para instalarlo necesitas PocketCode Pro.
Si tienes PocketCode instalado en tu Android, esto abre la página en la app.
Vista previa
Ficheros
README.md
main.py
pytest.ini
requirements-dev.txt
requirements.txt
shortener/__init__.py
shortener/app.py
shortener/codes.py
shortener/home.py
shortener/store.py
tests/test_links.pyREADME.md
# Link shortener: FastAPI + SQLite A small web API in Python with FastAPI: paste a long link, get a short code, and `/<code>` sends you on to the long one while it counts the clicks. Links are kept in SQLite (the `sqlite3` module that comes with Python). It has a one-page form at `/`, typed request and response models with Pydantic, input checks, and tests. ## Run it in PocketCode You need the app's Linux environment with Python 3.10 or newer and pip (the Developer pack in Terminal › Linux includes both). 1. Open the terminal in this project's folder (Open Terminal Here, in the editor menu). 2. Install FastAPI and the Uvicorn server (14 packages, versions pinned in `requirements.txt`; needs internet): ```sh python3 -m pip install --break-system-packages -r requirements.txt ``` 3. Start the server: ```sh python3 main.py ``` Or open `main.py` and tap Run (the Run panel should say Python 3 (Linux), since the packages are installed there). 4. Open http://localhost:8000 in the DevBrowser (or in the phone's browser) and shorten a link. The short link opens the long one. Stop it with Ctrl+C in the terminal, or Stop in the Run panel. Links are kept in `data/links.db`. If you prefer a virtual environment: `python3 -m venv .venv`, then `. .venv/bin/activate` and `pip install -r requirements.txt`. ## Try the API From a second terminal tab: ```shEsta vista previa está recortada. El contenido completo llega al instalarlo.
Cambios en la 1.0.0
Primera versión.