django-sequences
Generate gapless sequences of integer values.
What it is and what it does
django-sequences solves a compliance problem in Django applications: by default, Django's auto-incrementing primary keys can have gaps when transactions roll back, because most databases don't roll back their sequence counters for performance reasons. This happens on PostgreSQL, MySQL/MariaDB, Oracle, and SQLite. For use cases like accounting or invoicing where sequential, gapless numbering is legally or operationally required, these gaps are unacceptable.
The package provides a get_next_value function and a Sequence class that generate gapless integer sequences by leveraging database transaction integrity. You call get_next_value within a transaction, save its return value to the database in the same transaction, and the package guarantees no gaps. It supports multiple independent sequences, custom starting values, and looping sequences. The trade-off is that transactions calling get_next_value for the same sequence are serialized—other callers block until the transaction completes—so you should keep such transactions short.
Use it for:
- Generate invoice numbers that must be sequential and gapless for accounting compliance and audit trails.
- Create sequential case or ticket IDs in support systems where gaps would confuse users or violate reporting requirements.
- Produce sequential receipt or order numbers in point-of-sale or e-commerce systems with strict numbering policies.
- Maintain gapless sequence counters for regulatory or financial reporting where auditors expect continuous numbering.
- Batch-generate a range of sequential IDs for bulk operations using get_next_values while preserving transaction guarantees.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides gapless sequence generation for Django models, ensuring no gaps in integer primary keys even when transactions roll back.
Yes, if you need gapless sequences for compliance or operational reasons. The package is stable (Production/Stable classifier), has no known vulnerabilities, and integrates cleanly into Django with minimal friction. The aging maintenance status is not a blocker—the code is mature and the last commit is recent. The serialization trade-off is acceptable for most accounting and invoicing workloads where sequence calls are infrequent relative to overall transaction volume.
Install
django-sequences on PyPI
pip
pip install django-sequencesuv
uv add django-sequencespoetry
poetry add django-sequencesInstalling django-sequences
Before you install
Low friction install with a single runtime dependency on django. Maintenance status is aging—last release was 2024-01-31 and last commit 2026-01-05—but the repository remains active and unarchived with 246 stars.
License in practice
Released under BSD-3-Clause, a permissive open-source license. You may use, modify, and distribute the package freely in both commercial and private projects with minimal restrictions.
Quickstart
pip install django-sequences
# Add to INSTALLED_APPS: "sequences.apps.SequencesConfig"
# Run: django-admin migrate
from django.db import transaction
from sequences import get_next_value
with transaction.atomic():
Invoice.objects.create(number=get_next_value("invoice_numbers"))
Requires Django 3.2+ and Python 3.8+. Guarantees apply only when get_next_value is called and its return value is saved to the database within the same transaction.
Verify before relying
- Performance impact of transaction serialization on high-concurrency workloads with many sequences.
- Whether the nowait=True parameter bug mentioned in the docs affects real-world usage patterns.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — django |
| Maintenance | aging — 926 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 253,098/month — #8,527 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_sequences-3.0-py3-none-any.whl
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
django-fernet-fields-v2Provides Fernet symmetric encryption for Django…
permissive · top 5,000 on PyPI
django-db-connection-poolProvides connection pooling for Django database…
permissive · top 15,000 on PyPI
django-add-default-valueProvides a Django migration operation to set…
permissive · top 15,000 on PyPI
django-pgmigratePrevents migration downtime by detecting and…
permissive · top 5,000 on PyPI
SQLAlchemy-JSONFieldProvides a SQLAlchemy column type for storing…
permissive · top 5,000 on PyPI
djfernetProvides Fernet symmetric encryption for Django…
permissive · top 15,000 on PyPI
django-cleanupAutomatically deletes old files when Django…
permissive · top 15,000 on PyPI
django-safedeleteProvides soft-delete functionality for Django…
permissive · top 5,000 on PyPI
fractional-indexingGenerates sortable string keys for inserting…
permissive · top 15,000 on PyPI
django-dirtyfieldsTracks which fields on a Django model instance…
permissive · top 15,000 on PyPI