Modelo de projeto·Pro
Encurtador de links com FastAPI
Um encurtador de links em Python com FastAPI e SQLite. Cria códigos curtos, redireciona e conta os cliques, e tem um formulário de uma página e testes com pytest. Precisa do Python 3.10 ou mais recente com pip no ambiente Linux; instala 14 pacotes com versão fixa.
Para instalar, você precisa do PocketCode Pro.
Se o PocketCode estiver instalado no seu Android, isto abre a página no app.
Prévia
Arquivos
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 prévia está encurtada. O conteúdo completo vem com a instalação.
Mudanças na 1.0.0
Primeira versão.