Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/dev2forge/BasicReturns/llms.txt

Use this file to discover all available pages before exploring further.

BasicReturns gives every function in your Python application a predictable, structured return value. Instead of raising exceptions in some places, returning tuples in others, and using None as a sentinel elsewhere, you return a BasicReturn or DataAndMsgReturn object that always carries an ok flag, an optional error, and optional msg and data fields.

Quickstart

Get BasicReturns installed and write your first unified return in under five minutes.

Return Models

Learn about BasicReturn and DataAndMsgReturn — the two classes that power the library.

API Reference

Full class and method signatures extracted from source, with field types and defaults.

Best Practices

Patterns for consistent error handling, operation chaining, and serialisation.

Why BasicReturns?

Python functions return values in many inconsistent ways — raw tuples, bare exceptions, None, custom dicts, or ad-hoc dataclasses. BasicReturns standardises this with two Pydantic-backed models that work identically across every layer of your application.

Consistent Errors

Every function signals success or failure through a single ok boolean — no exception archaeology required.

Rich Context

Attach a human-readable msg and arbitrary data payload to every return value without inventing new types.

Type Safe

Full MyPy compatibility and a py.typed marker mean your IDE and CI pipeline catch misuse at the type level.

Serialisation Ready

to_dict() converts any return object to a plain dictionary, making JSON/API responses trivial.

Pydantic v2

Built on Pydantic 2 — validation, coercion, and schema generation come for free.

Python 3.8+

Supports Python 3.8 through 3.12 with no platform restrictions.

Quick Example

quickstart.py
from BasicReturns import DataAndMsgReturn

def divide(a: float, b: float) -> DataAndMsgReturn:
    response = DataAndMsgReturn()
    try:
        if b == 0:
            raise ZeroDivisionError("Cannot divide by zero")
        response.data = a / b
        response.msg = "Division completed successfully"
    except Exception as e:
        response.ok = False
        response.error = e
        response.msg = "Division failed"
    return response

result = divide(10, 2)
if result.ok:
    print(result.data)   # 5.0
else:
    print(result.error)
1

Install the package

pip install BasicReturns
2

Import the return model you need

from BasicReturns import BasicReturn, DataAndMsgReturn
3

Return structured values from your functions

Instantiate a return model, populate its fields, and return it. Check response.ok at the call site.
4

Serialise when needed

Call result.to_dict() to convert the return value to a plain dict for JSON responses or logging.

Build docs developers (and LLMs) love