Skip to main content

django-wee

PyPI - Version PyPI - Python Version

A minimal Django application for creating and resolving short URLs, backed by Sqids codes and Django's cache framework.


Table of Contents

Requirements

  • Python 3.10+
  • Django 5.2+

Installation

pip install django-wee

Add django_wee to INSTALLED_APPS and include its URL patterns:

# settings.py
INSTALLED_APPS = [
    ...
    "django_wee",
]
# urls.py
from django.urls import include, path

urlpatterns = [
    ...
    path("s/", include("django_wee.urls")),
]

Then run the migrations:

python manage.py migrate

ASGI / async projects

If your project runs under an ASGI server, use the async URL module instead:

(path("s/", include("django_wee.urls_async")),)

Configuration

No mandatory configuration is required. See Settings reference for optional tunables.

Usage

Creating short URLs

Use the provided shortcut functions anywhere in your code:

from django_wee.shortcuts import create_short_url

short_path = create_short_url("https://example.com/a/very/long/url")
# → "/s/aBcD1234/"

Pass an optional timezone-aware expiration datetime to create a URL that stops resolving after the specified time:

from datetime import timedelta

from django.utils import timezone

from django_wee.shortcuts import create_short_url

expiration = timezone.now() + timedelta(days=7)
short_path = create_short_url("https://example.com/a/very/long/url", expiration)

If no expiration is provided, the short URL does not expire.

An async variant is also available:

from datetime import timedelta

from django.utils import timezone

from django_wee.shortcuts import acreate_short_url

expiration = timezone.now() + timedelta(days=7)
short_path = await acreate_short_url("https://example.com/a/very/long/url", expiration)

Both functions validate the URL, persist a ShortUrl record, populate the cache, and return the relative redirect path.

Resolving short URLs

Requests to GET /s/<code>/ are handled automatically by the redirect view. The view checks the cache first and falls back to the database. Expired short URLs are not resolved. The response type (301 or 302) is controlled by the WEE_PERMANENT_REDIRECT setting.

Settings reference

Setting Default Description
WEE_CACHE_ALIAS "default" Cache alias (from CACHES) used to store short-URL mappings.
WEE_CACHE_TIMEOUT 3600 Cache TTL in seconds.
WEE_CACHE_PREFIX "WEE" Prefix used for short-URL cache keys. Keys use the prefix:code format.
WEE_MIN_LEN 8 Minimum length of the generated Sqids code.
WEE_ALPHABET Sqids default Character set used to generate codes.
WEE_PERMANENT_REDIRECT True If True, the redirect view returns HTTP 301; otherwise HTTP 302.

License

django-wee is distributed under the terms of the MIT license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_wee-0.0.1.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

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

django_wee-0.0.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file django_wee-0.0.1.tar.gz.

File metadata

  • Download URL: django_wee-0.0.1.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for django_wee-0.0.1.tar.gz
Algorithm Hash digest
SHA256 525b5dbc8f25dfcef035278db3403d2398bd0fea106a9525c371542444b70e2a
MD5 6a5b3cf798ce438f003106a79c865ea9
BLAKE2b-256 bfd9880a87edc1fb34d660347ee612b3fc137b7bce709272a91a0b59d28178c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_wee-0.0.1.tar.gz:

Publisher: release.yml on hartungstenio/django-wee

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

File details

Details for the file django_wee-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_wee-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for django_wee-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4dfc5411fd9b8af771d0f58cd1f6f9f8b5234e4696f160f0af1e369704b48468
MD5 2b87b477cf29772b05d9a1b391eb17f3
BLAKE2b-256 275aa7c82a6a3ee11273450424fba26fc20a5b74909cf713c87262fc674389f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_wee-0.0.1-py3-none-any.whl:

Publisher: release.yml on hartungstenio/django-wee

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

Release history Release notifications | RSS feed

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

This release

0.0.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page