Project template·Pro
FastAPI link shortener
A link shortener in Python with FastAPI and SQLite: it creates short codes, redirects and counts clicks. It comes with a one-page form and pytest tests. It needs Python 3.10 or newer with pip in the Linux environment and installs 14 pinned packages.
You need PocketCode Pro to install it.
If PocketCode is installed on your Android device, this opens the page in the app.
Preview
Files
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: ```shThis preview is shortened. You get the full content when you install it.
Changes in 1.0.0
First version.