--- id: django-sequences version: "3.0" license: BSD-3-Clause license_treatment: permissive maintenance: aging --- # django-sequences — Generate gapless sequences of integer values. License: permissive · Maintenance: aging · Downloads: 253.1K/mo ## 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 above — 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 pip install django-sequences uv add django-sequences 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_current - Install friction: low - Maintenance: aging - Downloads: 253.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags gapless sequence generation django, guaranteed sequential primary keys, transaction-safe integer sequences, django accounting invoice numbers, no-gap auto-increment, sequential id generation django, compliance-safe primary keys, django-extension, sequence-generation, compliance [View on SkillFed](https://skillfed.io/packages/django-sequences) · [View on PyPI](https://pypi.org/project/django-sequences/)