A simple URL shortener service.
Project description
urlshortener
A self-hosted URL shortener. Shorten a URL, get a redirect, track visit counts. That's it.
API
| Method | Path | Description |
|---|---|---|
POST |
/shorten |
Create a short link |
GET |
/{code} |
Redirect to original URL (307) |
GET |
/stats/{code} |
Visit count + original URL |
GET |
/healthz |
Liveness + DB connectivity check |
# shorten
curl -X POST http://localhost:8000/shorten \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/some/long/path"}'
# {"code": "aB3kR7z", "short_url": "http://localhost:8000/aB3kR7z"}
# stats
curl http://localhost:8000/stats/aB3kR7z
# {"code": "aB3kR7z", "url": "https://example.com/some/long/path", "visits": 4}
Running locally
Prerequisites: Python 3.11, a running PostgreSQL instance.
pip install -e .
# point at your DB (or rely on the default below)
export URLSHORTENER_DATABASE_URL="postgresql+psycopg://user:pass@localhost:5432/urlshortener"
urlshortener serve
# listening on http://127.0.0.1:8000
Docker Compose
Spins up Postgres + app together:
docker compose up -d
Configuration
All settings are environment variables with the URLSHORTENER_ prefix.
| Variable | Default | Description |
|---|---|---|
URLSHORTENER_DATABASE_URL |
postgresql+psycopg://urlshortener:urlshortener@localhost:5432/urlshortener |
SQLAlchemy connection string |
URLSHORTENER_BASE_URL |
http://localhost:8000 |
Public base URL used when building short links |
URLSHORTENER_HOST |
127.0.0.1 |
Bind address |
URLSHORTENER_PORT |
8000 |
Bind port |
URLSHORTENER_CODE_LENGTH |
7 |
Length of generated short codes (4–32) |
URLSHORTENER_LOG_LEVEL |
INFO |
Root log level |
Development
pip install -e ".[test]"
pytest # runs tests + coverage
mypy src # strict type checking
Tests use an in-memory fake store
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.4.tar.gz.
File metadata
- Download URL: bh_urlshortener-0.0.4.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
483030edc7828eab5648b32bc686b5e2d918da2b73c4aee7867b7f953155a4b6
|
|
| MD5 |
6fae2d4eb4af8e931d09450241b8a532
|
|
| BLAKE2b-256 |
7e57759053090d694e6856ddc95b6c347888bea35c4178fdc64e827c3605a316
|
Provenance
The following attestation bundles were made for bh_urlshortener-0.0.4.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.4.tar.gz -
Subject digest:
483030edc7828eab5648b32bc686b5e2d918da2b73c4aee7867b7f953155a4b6 - Sigstore transparency entry: 1853565193
- Sigstore integration time:
-
Permalink:
abin-m/urlshortener@bb4abeb97f848b392b5e5be9a692231cef4679b4 -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/abin-m
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bb4abeb97f848b392b5e5be9a692231cef4679b4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bh_urlshortener-0.0.4-py3-none-any.whl.
File metadata
- Download URL: bh_urlshortener-0.0.4-py3-none-any.whl
- Upload date:
- Size: 7.2 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 |
d4a97c3c586f282f7ff9ec6f9d60c42259d6cb804605880afbeff22d4837d3fc
|
|
| MD5 |
cf5516577c570658d5b8e6beb8baa837
|
|
| BLAKE2b-256 |
088993c5a51a4cd0c8d9d44bb0856acef00e340fff4c6a0057701ef7a82dab93
|
Provenance
The following attestation bundles were made for bh_urlshortener-0.0.4-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.4-py3-none-any.whl -
Subject digest:
d4a97c3c586f282f7ff9ec6f9d60c42259d6cb804605880afbeff22d4837d3fc - Sigstore transparency entry: 1853565216
- Sigstore integration time:
-
Permalink:
abin-m/urlshortener@bb4abeb97f848b392b5e5be9a692231cef4679b4 -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/abin-m
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bb4abeb97f848b392b5e5be9a692231cef4679b4 -
Trigger Event:
push
-
Statement type: