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.
BasicReturn is the foundation of the BasicReturns library. It is a Pydantic v2 BaseModel subclass that represents the outcome of any operation — success or failure — in a consistent, type-safe structure. Every function that uses BasicReturns returns at minimum an instance of BasicReturn, giving callers a predictable interface regardless of what the function does internally.
Import
Class Definition
Fields
True when the operation succeeded; set to False on failure. Mirrors the
semantics of an HTTP success response — a truthy value signals the caller that
the operation completed without error.Holds the exception or error object when
ok is False. Remains None on
success. Accepts any Python value — an Exception subclass, a string
message, or any custom error object.Methods
to_dict()
Returns a plain Python dictionary representation of the instance. This is
useful at serialization boundaries — for example, before passing the return
value to json.dumps() or a web framework response helper.
Return type: dict
__str__()
Returns a human-readable, multi-line string representation of the instance.
Handy for logging and debugging.
Return type: strFormat:
OK: {ok}\nError: {error}
Usage Example
The canonical pattern is to wrap the body of a function in atry/except block
and return a BasicReturn in both branches. Callers can then check result.ok
before proceeding.
When to Use BasicReturn vs DataAndMsgReturn
| Scenario | Recommended class |
|---|---|
| Write, delete, send, or any fire-and-forget operation | BasicReturn |
| Operation that returns a result payload or a message | DataAndMsgReturn |
| Lightweight success/failure signal with no extra context | BasicReturn |
API handler that needs structured JSON with msg and data | DataAndMsgReturn |
BasicReturn when the operation’s only meaningful outcome is whether it
succeeded or failed — there is no data to return to the caller. If you find
yourself stuffing results into the error field on success, that is a clear
signal to switch to DataAndMsgReturn instead.
BasicReturn extends Pydantic’s BaseModel, so you can construct it with
keyword arguments just like any other Pydantic model: