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 codebase a predictable return structure. Instead of scattered tuples, naked exceptions, or ad-hoc dictionaries, you get two Pydantic-backed models — BasicReturn and DataAndMsgReturn — that express success, failure, messages, and payloads in one unified interface.

Introduction

Understand the problem BasicReturns solves and how its two return types work together.

Quickstart

Install the package and write your first function with a unified return in under five minutes.

Guides

Practical patterns for error handling, chaining operations, and API integration.

API Reference

Full class documentation for BasicReturn and DataAndMsgReturn with all fields and methods.

Why BasicReturns?

Python functions can return anything — a value, a tuple, None, or raise an exception. When a codebase mixes all of these patterns, every call site must guess what it might get back. BasicReturns solves this by providing two lightweight Pydantic models that every function can return instead.

Consistent Shape

Every function returns the same fields — callers always know what to expect.

No Unhandled Exceptions

Capture errors in the error field instead of letting exceptions bubble unpredictably.

Type Safe

Full MyPy compatibility and Pydantic v2 validation out of the box.

Get started in seconds

1

Install from PyPI

pip install BasicReturns
2

Import the return types

from BasicReturns import BasicReturn, DataAndMsgReturn
3

Use in your functions

def divide(a: float, b: float) -> DataAndMsgReturn:
    response = DataAndMsgReturn()
    try:
        response.data = a / b
        response.msg = "Division successful"
    except Exception as e:
        response.ok = False
        response.error = e
        response.msg = "Division failed"
    return response
4

Handle the result uniformly

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

Build docs developers (and LLMs) love