Private, Secure, and Free Shortlinks
A simple, high-performance URL shortener built with Python and FastAPI. It uses the Hashids library to generate short, non-sequential, and unique codes from database IDs, providing a clean and secure way to shorten links.
- Obfuscated & Reversible IDs: Uses the Hashids library to convert sequential database IDs into short, non-sequential, and URL-safe codes.
- Link Expiration (TTL): Set links to expire after a specific duration (1 hour, 24 hours, 1 week) or never.
- Link Previews: Enhances user security by providing a preview page (
/get/<hash>) to show the destination URL before redirecting. - Persistent & Scalable Storage: Uses a file-based SQLite database that persists across server restarts.
- Privacy-Focused: No tracking or analytics. Just simple, fast redirects.
- Spam Protection: Implements API rate limiting to prevent abuse.
- Automatic Internationalization: The UI automatically detects the user's browser language and displays one of 9 supported languages.
- Production-Ready: Includes a health check endpoint and is configured for easy deployment on platforms like Render.
!Python !FastAPI !SQLite !JavaScript !HTML5 !CSS3
-
Clone the repository:
git clone https://github.com/tripping-alien/shortlink.git cd shortlink -
Create and activate a virtual environment:
python -m venv .venv # On macOS/Linux: source .venv/bin/activate # On Windows (Command Prompt/PowerShell): .\.venv\Scripts\activate
-
Install dependencies and run the server:
pip install -r requirements.txt python -m uvicorn app:app --host 0.0.0.0 --port 8000 --reload
-
Access the application:
- Open your web browser and navigate to
http://localhost:8000.
- Open your web browser and navigate to
This project is configured for easy deployment on a platform like Render.
-
Create a new Web Service on Render and connect it to your GitHub repository.
-
Set the Start Command to:
- Build Command:
pip install -r requirements.txt - Start Command:
uvicorn app:app --host 0.0.0.0 --port $PORT
Note: The build command ensures all your Python dependencies are installed before the server starts.
- Build Command:
-
Add Environment Variables:
PYTHON_VERSION:3.11(or your desired Python version).HASHIDS_SALT: A long, random, and secret string. This is critical for security and should be set in your production environment. You can generate one locally using the command:Note: For local development, if this variable is not set, the application will automatically generate and use a stablepython -c "import secrets; print(secrets.token_hex(32))".saltfile.BASE_URL: The public URL of your web service (e.g.,https://shortlinks.art).
-
Add a Persistent Disk to store the
shortlinks.dbfile.- Name:
data-disk - Mount Path:
/var/data - The application is configured to use the
RENDER_DISK_PATHenvironment variable, which Render automatically sets to this mount path.
- Name:
-
Update the Health Check Path in your service settings to
/health.
- Andrey Lopukhov - tripping-alien
This project is open source and released under the MIT License.