Skip to main content

A simple URL shortener service.

Project description

urlshortener

Self-hosted URL shortener. Shorten URLs, redirect, track visits.

Quickstart

Docker Compose (recommended)

cp .env.example .env   # 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

bh_urlshortener-0.0.6.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bh_urlshortener-0.0.6-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file bh_urlshortener-0.0.6.tar.gz.

File metadata

  • Download URL: bh_urlshortener-0.0.6.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

Hashes for bh_urlshortener-0.0.6.tar.gz
Algorithm Hash digest
SHA256 504151fade4aee0ad06fc3eb2b979a151d529924470095a221fe391a104b07f0
MD5 f747e8cc167974a7a0db3ae807931312
BLAKE2b-256 3f7ce6bcab68d95b62f3d9e8b8195c3ad2bb0fdd81275ffa72182096ac4e664c

See more details on using hashes here.

Provenance

The following attestation bundles were made for bh_urlshortener-0.0.6.tar.gz:

Publisher: release.yml on abin-m/urlshortener

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bh_urlshortener-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for bh_urlshortener-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ec2bbcc4fb8d95091993acd029ab7efbfc7c43052e6db9333c3ec227128895e5
MD5 2aaa7f75218ee94683fdb3d3f12150cd
BLAKE2b-256 8e5f183aef8c87e68649d715e46e08f6244b00c3ccf34c0b4c6cc2904f71dd0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for bh_urlshortener-0.0.6-py3-none-any.whl:

Publisher: release.yml on abin-m/urlshortener

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page