skillfed

django-sequences

Generate gapless sequences of integer values.

django-sequences v3.0 253.1K downloads/30d#8,527 on PyPI246
Permissive license BSD-3-Clause AGING released

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-sequences

uv

uv add django-sequences

poetry

poetry add django-sequences

Installing 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

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 3.2Framework :: Django :: 4.0Framework :: Django :: 4.1Framework :: Django :: 4.2Framework :: Django :: 5.0Intended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

gapless sequence generation djangoguaranteed sequential primary keystransaction-safe integer sequencesdjango accounting invoice numbersno-gap auto-incrementsequential id generation djangocompliance-safe primary keys
django-extensionsequence-generationcompliance

More Database packages

psycopg2-binary

psycopg2-binary is a PostgreSQL database…

copyleft · top 1,000 on PyPI

redis

Python client library for connecting to and…

permissive · top 1,000 on PyPI

ydb

YDB Python SDK is the official client library…

permissive · top 1,000 on PyPI

snowflake-connector-python

Connects Python applications to Snowflake data…

permissive · top 1,000 on PyPI

sqlparse

sqlparse tokenizes SQL text into a tree of…

permissive · top 1,000 on PyPI

dbt-adapters

Provides base adapter protocols and shared…

permissive · top 1,000 on PyPI

django-fernet-fields-v2

Provides Fernet symmetric encryption for Django…

permissive · top 5,000 on PyPI

django-db-connection-pool

Provides connection pooling for Django database…

permissive · top 15,000 on PyPI

django-add-default-value

Provides a Django migration operation to set…

permissive · top 15,000 on PyPI

django-pgmigrate

Prevents migration downtime by detecting and…

permissive · top 5,000 on PyPI

SQLAlchemy-JSONField

Provides a SQLAlchemy column type for storing…

permissive · top 5,000 on PyPI

djfernet

Provides Fernet symmetric encryption for Django…

permissive · top 15,000 on PyPI

django-cleanup

Automatically deletes old files when Django…

permissive · top 15,000 on PyPI

django-safedelete

Provides soft-delete functionality for Django…

permissive · top 5,000 on PyPI

fractional-indexing

Generates sortable string keys for inserting…

permissive · top 15,000 on PyPI

django-dirtyfields

Tracks which fields on a Django model instance…

permissive · top 15,000 on PyPI