A simple Python Flask URL shortener with SQLite storage, custom alias validation, click analytics, and a REST API.
-
Create a virtual environment:
python -m venv .venv .\.venv\Scripts\Activate.ps1 -
Install dependencies:
pip install -r requirements.txt -
Run the app:
python app.py
-
Open
http://127.0.0.1:5000in your browser.
- Shorten URLs with a generated code.
- Optional custom alias support.
- Click counting for each short link.
- Recent links view with analytics.
- REST API for programmatic creation and inspection.
POST http://127.0.0.1:5000/api/shorten
Request JSON:
{
"long_url": "https://example.com/page",
"custom_alias": "example-link"
}Response JSON:
{
"code": "example-link",
"long_url": "https://example.com/page",
"short_url": "http://127.0.0.1:5000/example-link",
"clicks": 0
}GET http://127.0.0.1:5000/api/urls/<code>
Response JSON includes code, long_url, clicks, and short_url.
This project includes a Dockerfile and Procfile, so it can run on AWS Elastic Beanstalk with Docker or the Python platform.
-
Install and configure the AWS CLI and EB CLI.
-
Initialize the app:
eb init -p docker url-shortener-app
-
Create and deploy an environment:
eb create url-shortener-prod eb deploy
-
Open the deployed site:
eb open
If you prefer the Python platform, Elastic Beanstalk can use requirements.txt, app.py, and Procfile directly.
-
Initialize with Python:
eb init -p python-3.12 url-shortener-app
-
Deploy as above.
- Build and push the Docker image to ECR.
- Create an ECS service with the image.
- Expose port
5000via a load balancer.
urls.dbis a local SQLite file. For production, use a networked database like Amazon RDS or DynamoDB if you need durability across container restarts and multiple instances.
- Custom alias validation: 3-32 characters, letters, numbers, hyphens, and underscores.
- Data is stored in
urls.dbby default.