Skip to main content

PyPI release Downloads Coverage Linting Coding Style Documentation Status

Race-safe state machines for Django models: a protected PhaseField, transitions as one conditional UPDATE, and guards that tell humans and machines why an action was refused.

PyPI • GitHub • Full documentation

Creator & Maintainer: Beyonder Deutschland

Features

  • Declare the allowed transitions once, as a table on the field
  • Assigning the phase directly raises; only move() and move_many() change it
  • move() writes phase and further fields in one conditional UPDATE, so of two concurrent transitions from the same phase exactly one succeeds
  • move_many() moves a whole queryset from one phase to another with one conditional UPDATE, checked against the same table
  • Every save() is guarded against a stale phase, so it can't silently undo a concurrent transition
  • Phases as strings (PhaseField) or numbers (IntegerPhaseField); migrations see a plain Django field and never import phase
  • System checks catch a missing mixin, a second phase field, a nullable one or one inherited from a concrete parent model
  • PhaseGuardError gives refused actions a stable code for machines and a detail for humans
  • Overrides no private Django method
from django.db import models
from django.utils import timezone

from phase.fields import PhaseField
from phase.mixins.phase_guard import PhaseGuardMixin
from phase.transitions import move


class Order(PhaseGuardMixin, models.Model):
    class Status(models.TextChoices):
        OPEN = "open"
        PAID = "paid"
        SHIPPED = "shipped"
        CANCELLED = "cancelled"

    status = PhaseField(
        max_length=10,
        choices=Status.choices,
        default=Status.OPEN,
        transitions={
            Status.OPEN: (Status.PAID, Status.CANCELLED),
            Status.PAID: (Status.SHIPPED,),
        },
    )
    paid_at = models.DateTimeField(null=True, blank=True)


order = Order.objects.create()
move(obj=order, to=Order.Status.PAID, paid_at=timezone.now())

order.status = Order.Status.OPEN  # raises ProtectedPhaseFieldError
move(obj=order, to=Order.Status.OPEN)  # raises IllegalPhaseTransitionError

Installation

  • Install the package via pip:

    pip install django_phase

    or via uv:

    uv add django_phase

  • Add module to INSTALLED_APPS within the main django settings.py:

INSTALLED_APPS = (
    # ...
    "phase",
)

Releasing a new version

Releases are fully automated. Push a version tag and the pipeline will build, sign with Sigstore, publish to PyPI via Trusted Publishing, and create a GitHub Release — no API tokens needed.

git tag v<version>          # e.g. git tag v1.2.3
git push origin v<version>

Tags must start with v. Tags without the prefix won't trigger the pipeline.

First-time setup

Before the pipeline can run for the first time, an admin must:

  1. Create GitHub Environment pypi

    • Go to Settings → Environments → New environment, name it exactly pypi
    • Under Deployment branches and tags, add a tag rule with pattern v*
    • Optionally add required reviewers for a manual approval gate
  2. Configure PyPI Trusted Publisher

    • Go to PyPI → Project settings → Publishing → Add a new publisher
    • Fill in: Owner beyonder-deutschland, Repository django-phase, Workflow release.yml, Environment pypi

Publish to ReadTheDocs.io

  • Fetch the latest changes in GitHub mirror and push them
  • Trigger new build at ReadTheDocs.io (follow instructions in admin panel at RTD) if the GitHub webhook is not yet set up.

Maintenance

Please note that this package supports the ambient-package-update. So you don't have to worry about the maintenance of this package. This updater is rendering all important configuration and setup files. It works similar to well-known updaters like pyupgrade or django-upgrade.

To run an update, refer to the documentation page of the "ambient-package-update".

Metadata

Release files for django-phase 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-phase 0.3.0
File Size Uploaded Provenance Actions
django_phase-0.3.0.tar.gz 39.1 kB With provenance Details for django_phase-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-phase 0.3.0
File Interpreter ABI Platform Actions
django_phase-0.3.0-py3-none-any.whl Python 3 none any Details for django_phase-0.3.0-py3-none-any.whl

Total release size: 53.7 kB

Release files / django_phase-0.3.0.tar.gz

Download URL django_phase-0.3.0.tar.gz
Size 39.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1fb4b32a233a9b8f15e6bd8a818e2ea2cf29dd60e8762b1fd00f2054949dbccb
BLAKE2b-256 checksum
How to use checksums
f231bcb7c241b36099682b4acfd892045bdd317e5ee9449bbe0602fd6b554fda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / django_phase-0.3.0-py3-none-any.whl

Download URL django_phase-0.3.0-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8edc667e265626decfe7d5848ede1d6c36790b739d4f331483308736af5b8419
BLAKE2b-256 checksum
How to use checksums
5149ba3c609f902b306355a3094eb5fb9a672f9fc575329d1305724dea407e8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for django-phase 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_phase-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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