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() changes it
  • move() writes phase and further fields in one conditional UPDATE, so of two concurrent transitions from the same phase exactly one succeeds
  • Every save() is guarded against a stale phase, so it can't silently undo a concurrent transition
  • Migrations see a plain CharField and never import phase
  • System checks catch a missing mixin, a second phase field 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.1.1

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.1.1
File Size Uploaded Provenance Actions
django_phase-0.1.1.tar.gz 33.8 kB With provenance Details for django_phase-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 46.9 kB

Release files / django_phase-0.1.1.tar.gz

Download URL django_phase-0.1.1.tar.gz
Size 33.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0c9637610376bad96a3e7db52aa98f49f32813da9d97afac0a567f62bdd125b5
BLAKE2b-256 checksum
How to use checksums
94560f020e4741106be4b8b2d9032b0d6690f3724d13ae4ea0110223fb3d5ffe
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.1.1-py3-none-any.whl

Download URL django_phase-0.1.1-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e603662f76750330fccea6cf6a865fcce5c272af66ba4d7a2459d5284f69888
BLAKE2b-256 checksum
How to use checksums
4f8a1695a5a0e600c331f99ebdde9964f9d20c73d7436893ca634aa4616c11c2
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.1.1

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.1.1.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