django-returns
Meaningful Django utils based on Functional Programming.
Made possible by returns
Install
pip install django-returns
What
django-returns is a tiny layer on top of Django’s ORM that lets you opt into
returns containers when you want explicit success/failure return types
instead of exceptions.
Why
To bring the benefits of Functional Programming to the Django world.
- Improved predictability, understandability, maintainability.
- Safer code with type checking.
- Better error handling.
How
By subclassing QuerySet and applying returns decorators to its methods.
Note: the default ReturnsManager does not change Django semantics. It keeps the original methods intact and adds new ones:
*_resultvariants for sync operations (returnSuccess/Failure)*_ioresultvariants for both sync and async operations (returnIOSuccess/IOFailure)first_maybe()/last_maybe()for "might beNone" QS methods (returnSome/Nothing)
Safe ORM
Enable it by using the provided base model.
from django_returns.models import ReturnsModel
class Person(ReturnsModel):
name = models.CharField(max_length=255, unique=True)
Or by using the custom Manager.
from django_returns.managers import ReturnsManager
class Person(models.Model):
objects = ReturnsManager()
Basic Usage
Methods with the _result suffix return returns.result.Result.
from returns.result import Failure, Result, Success
def get_person_name(person_id):
result: Result = Person.objects.get_result(id=person_id)
match result:
case Success(person):
return Success(person.name)
case Failure(Person.DoesNotExist()):
return ""
IO Methods
Async/IO *_ioresult methods return an IO-wrapped result (IOSuccess / IOFailure).
from returns.io import unsafe_perform_io
from returns.result import Failure, Success
async def get_person_id_async(name):
io_result = await Person.objects.aget_ioresult(name=name)
result = unsafe_perform_io(io_result)
match result:
case Success(person):
return person.id
case Failure(error):
return -1
Metadata
Release files for django-returns 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_returns-0.2.2.tar.gz | 29.9 kB | With provenance | Details for django_returns-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_returns-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for django_returns-0.2.2-py3-none-any.whl |
Total release size: 49.5 kB
Release files / django_returns-0.2.2.tar.gz
| Download URL | django_returns-0.2.2.tar.gz |
|---|---|
| Size | 29.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f26d273e29b25affd33b324aa70139430cf491fdeadd79a579666b157ab4b1c6
|
|
BLAKE2b-256 checksum How to use checksums |
29140fbd2024fd3ea6b44d5913ae0dd0b8fad33c577c042496d6b6aea5045d62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Jan 23, 2026.
Transparency logRelease files / django_returns-0.2.2-py3-none-any.whl
| Download URL | django_returns-0.2.2-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3cd019bb9ff13df62e0c8f91bc2d5792a5fa3cefc74bb512b575c8d232af31d4
|
|
BLAKE2b-256 checksum How to use checksums |
ce61d4756a4b2599b0b6a0dbf63bcd13b70ec8c2092f1aac2a340bed8dc21acb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Jan 23, 2026.
Transparency logSecurity for django-returns 0.2.2
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.
Attestation for django_returns-0.2.2.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 Jan 23, 2026.
Transparency logA 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.