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)

# 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

bh_urlshortener-0.0.7.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.7-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

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

Hashes for bh_urlshortener-0.0.7.tar.gz
Algorithm Hash digest
SHA256 a900214e9088bf1c974031f3487dd461e4d4900f787f38cf4733b5fa6cdc7a45
MD5 bc0c4f59e83e5fe090c1b2174f9f2f16
BLAKE2b-256 318bc12088186e826304f538a5f875d1d0d84cc84ea7ecb4d0dd1a648fd1c27c

See more details on using hashes here.

Provenance

The following attestation bundles were made for bh_urlshortener-0.0.7.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.7-py3-none-any.whl.

File metadata

File hashes

Hashes for bh_urlshortener-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ab19e2a593fc1acc2ba46f4ae33cccfe25b7b9968063b6867e17582d2fa4ecfe
MD5 a4ce0b573dd37436539b911ef7646ccc
BLAKE2b-256 aa6161719f01d2637428b423598c864ed80e74c2ef0891262e4b8bc9a375d978

See more details on using hashes here.

Provenance

The following attestation bundles were made for bh_urlshortener-0.0.7-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