A simple URL shortener service.
Project description
urlshortener
Self-hosted URL shortener. Shorten URLs, redirect, track visits.
Quickstart
Docker Compose (recommended)
# create an .env file by following the configs docs
# set POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB
docker compose up -d
Local
pip install -e .
export URLSHORTENER_DATABASE_URL="postgresql+psycopg://user:pass@localhost:5432/urlshortener"
urlshortener serve
App runs at http://localhost:8000.
API
| Method | Path | Description |
|---|---|---|
| POST | /shorten |
Create short link |
| GET | /{code} |
Redirect to original (307) |
| GET | /stats/{code} |
Visit count + original URL |
| GET | /healthz |
Liveness + DB check |
| GET | /metrics |
Prometheus metrics |
curl -X POST http://localhost:8000/shorten \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/long/path"}'
# {"code": "aB3kR7z", "short_url": "http://localhost:8000/aB3kR7z"}
curl http://localhost:8000/stats/aB3kR7z
# {"code": "aB3kR7z", "url": "https://example.com/long/path", "visits": 4}
Development
pip install -e ".[test]"
pytest # test + coverage
mypy src # type check
tox # full matrix
Tests run against an in-memory fake store — no DB required.
Observability
Docker Compose includes Prometheus, Alertmanager, and Grafana.
| Service | URL |
|---|---|
| Grafana | http://localhost:3000 |
| Prometheus | http://localhost:9090 |
| Alertmanager | http://localhost:9093 |
See docs/05_observability.md for details.
Docs
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bh_urlshortener-0.0.7.tar.gz.
File metadata
- Download URL: bh_urlshortener-0.0.7.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a900214e9088bf1c974031f3487dd461e4d4900f787f38cf4733b5fa6cdc7a45
|
|
| MD5 |
bc0c4f59e83e5fe090c1b2174f9f2f16
|
|
| BLAKE2b-256 |
318bc12088186e826304f538a5f875d1d0d84cc84ea7ecb4d0dd1a648fd1c27c
|
Provenance
The following attestation bundles were made for bh_urlshortener-0.0.7.tar.gz:
Publisher:
release.yml on abin-m/urlshortener
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bh_urlshortener-0.0.7.tar.gz -
Subject digest:
a900214e9088bf1c974031f3487dd461e4d4900f787f38cf4733b5fa6cdc7a45 - Sigstore transparency entry: 1869189412
- Sigstore integration time:
-
Permalink:
abin-m/urlshortener@8664b78181c956c31f3bfb49fd3226b9982651d1 -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/abin-m
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8664b78181c956c31f3bfb49fd3226b9982651d1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bh_urlshortener-0.0.7-py3-none-any.whl.
File metadata
- Download URL: bh_urlshortener-0.0.7-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab19e2a593fc1acc2ba46f4ae33cccfe25b7b9968063b6867e17582d2fa4ecfe
|
|
| MD5 |
a4ce0b573dd37436539b911ef7646ccc
|
|
| BLAKE2b-256 |
aa6161719f01d2637428b423598c864ed80e74c2ef0891262e4b8bc9a375d978
|
Provenance
The following attestation bundles were made for bh_urlshortener-0.0.7-py3-none-any.whl:
Publisher:
release.yml on abin-m/urlshortener
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bh_urlshortener-0.0.7-py3-none-any.whl -
Subject digest:
ab19e2a593fc1acc2ba46f4ae33cccfe25b7b9968063b6867e17582d2fa4ecfe - Sigstore transparency entry: 1869189494
- Sigstore integration time:
-
Permalink:
abin-m/urlshortener@8664b78181c956c31f3bfb49fd3226b9982651d1 -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/abin-m
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8664b78181c956c31f3bfb49fd3226b9982651d1 -
Trigger Event:
push
-
Statement type: