A settlement engine for collaborative projects. Calculate fair payouts when multiple people collaborate with shared revenue and individual expenses.
Project description
Braid Formula
A settlement engine for collaborative projects.
What is this?
When people collaborate on a project—a workshop, an event, a pop-up—someone has to figure out who gets paid what. It's not just "split the revenue." Real collaborations involve:
- Different expense amounts per person
- Different profit-sharing percentages
- The need to reimburse everyone for what they spent
- Handling losses fairly when things don't go as planned
The Braid Formula handles all of this.
Installation
pip install braid-formula
Quick Start
from braid_formula import settle
result = settle(
revenue=120.00,
collaborators=[
{"name": "J", "split_percent": 50, "expenses": 151.15},
{"name": "Z", "split_percent": 50, "expenses": 90.49},
]
)
for c in result.collaborators:
print(f"{c.name} gets ${c.payout}")
# Output:
# J gets $90.33
# Z gets $29.67
Even simpler:
from braid_formula import quick_settle
payouts = quick_settle(
revenue=120,
splits={"J": 50, "Z": 50},
expenses={"J": 151.15, "Z": 90.49}
)
print(payouts)
# {'J': 90.33, 'Z': 29.67}
The Math
The Braid Formula calculates fair settlements in three steps:
Step 1: Calculate Net Profit (or Loss)
Net Profit = Revenue - Total Expenses
Step 2: Calculate Each Person's Profit Share
Profit Share = Net Profit × (Split % / 100)
Step 3: Calculate Payout
Payout = Expenses + Profit Share
That's it. Everyone gets reimbursed for what they spent, then profit (or loss) is split according to the agreed percentages.
Real Example: The Floral Workshop
J and Z run a floral arrangement workshop together:
| Person | Split | Expenses |
|---|---|---|
| J | 50% | $151.15 |
| Z | 50% | $90.49 |
They collect $120 in revenue.
Step 1: Net Profit
Total Expenses = $151.15 + $90.49 = $241.64
Net Profit = $120 - $241.64 = -$121.64 (a loss)
Step 2: Profit Share (Loss Share)
J's share = -$121.64 × 0.50 = -$60.82
Z's share = -$121.64 × 0.50 = -$60.82
Step 3: Payouts
J's payout = $151.15 + (-$60.82) = $90.33
Z's payout = $90.49 + (-$60.82) = $29.67
Result: J gets $90.33, Z gets $29.67. The $120 revenue is distributed, and the loss is shared equally.
Command Line Usage
# Simple calculation
braid --revenue 120 --collab "J:50:151.15" --collab "Z:50:90.49"
# Interactive mode
braid --interactive
# JSON output
braid -r 1000 -c "Alice:60:500" -c "Bob:40:200" --json
API Reference
settle(revenue, collaborators, ...)
The main settlement function.
Parameters:
revenue(number): Total revenue from the projectcollaborators(list): List of collaborators, each with:name(str): Person's namesplit_percent(number): Their percentage share (must sum to 100)expenses(number, optional): What they spent (default 0)
allow_negative_revenue(bool): Allow refund scenarios (default False)validate(bool): Validate inputs (default True)
Returns: SettlementResult with:
revenue: Total revenuetotal_expenses: Sum of all expensesnet_profit: Revenue minus expensesis_profitable: True if net_profit >= 0collaborators: List ofCollaboratorResultobjects
quick_settle(revenue, splits, expenses)
Simplified interface returning just the payouts.
quick_settle(
revenue=1000,
splits={"Alice": 60, "Bob": 40},
expenses={"Alice": 200, "Bob": 100}
)
# Returns: {'Alice': 620.0, 'Bob': 380.0}
Handling Edge Cases
Negative Payouts
If someone's share of the loss exceeds their expenses, they'll have a negative payout—meaning they owe money to the other collaborators.
result = settle(
revenue=100,
collaborators=[
{"name": "A", "split_percent": 50, "expenses": 10},
{"name": "B", "split_percent": 50, "expenses": 190},
]
)
# A's payout: -$40 (owes $40)
# B's payout: $140
Zero Revenue
result = settle(
revenue=0,
collaborators=[
{"name": "A", "split_percent": 50, "expenses": 100},
{"name": "B", "split_percent": 50, "expenses": 100},
]
)
# Both get $0 (nothing to distribute)
Unequal Splits
result = settle(
revenue=1000,
collaborators=[
{"name": "Lead", "split_percent": 70, "expenses": 200},
{"name": "Support", "split_percent": 30, "expenses": 100},
]
)
# Net profit: $700
# Lead: $200 + ($700 × 0.70) = $690
# Support: $100 + ($700 × 0.30) = $310
Validation
The formula validates inputs and raises descriptive errors:
from braid_formula import settle, SplitPercentageError
try:
settle(revenue=100, collaborators=[
{"name": "A", "split_percent": 60},
{"name": "B", "split_percent": 60}, # Total 120%!
])
except SplitPercentageError as e:
print(e) # "Split percentages must sum to 100%, got 120%"
Validation checks:
- At least one collaborator required
- Split percentages must sum to exactly 100
- Revenue cannot be negative (unless
allow_negative_revenue=True) - Expenses cannot be negative
- Collaborator names must be unique
Why "Braid"?
Like threads woven together, collaborations intertwine different contributions—time, money, skills—into something greater. The Braid Formula weaves these together into fair settlements.
Why Open Source?
The formula is transparent and auditable. Anyone can verify the math. Trust is built into the code.
The formula is free. Braid (the app) is for people who don't want to run Python scripts after a pottery class.
Contributing
Contributions welcome! Please:
- Fork the repo
- Create a feature branch
- Add tests for new functionality
- Run
pytest tests/to verify - Submit a PR
License
MIT License - see LICENSE for details.
Credits
Created by Afro-Panther.
Part of the Braid ecosystem for collaborative economics.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file braid_formula-0.1.1.tar.gz.
File metadata
- Download URL: braid_formula-0.1.1.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdbae997509ca06eb0b2ae98fd726e886422a98bb3fb1d4520ca9dce29450257
|
|
| MD5 |
ece69f4dbfe6e35584837d16e161a7a5
|
|
| BLAKE2b-256 |
3b838c6dbfe2883cf9f2fc2816f0c30b5b579e5a188a6aa85df17c100022456d
|
Provenance
The following attestation bundles were made for braid_formula-0.1.1.tar.gz:
Publisher:
publish.yml on afrotech-panther/braid-formula
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
braid_formula-0.1.1.tar.gz -
Subject digest:
fdbae997509ca06eb0b2ae98fd726e886422a98bb3fb1d4520ca9dce29450257 - Sigstore transparency entry: 766358616
- Sigstore integration time:
-
Permalink:
afrotech-panther/braid-formula@55800b4212c03835b08b1e78b061e63082bc82d2 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/afrotech-panther
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@55800b4212c03835b08b1e78b061e63082bc82d2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file braid_formula-0.1.1-py3-none-any.whl.
File metadata
- Download URL: braid_formula-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cc0a0183e779145f978a0b59bdd1ddeb3ecac397869c52307ddb9deadbae6fd
|
|
| MD5 |
68994a6e204173d048c4784eed31a898
|
|
| BLAKE2b-256 |
e6f65e67d3c1a7b987841572e01bf67d8796ca05ae73fe628b1e51b938f323d7
|
Provenance
The following attestation bundles were made for braid_formula-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on afrotech-panther/braid-formula
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
braid_formula-0.1.1-py3-none-any.whl -
Subject digest:
1cc0a0183e779145f978a0b59bdd1ddeb3ecac397869c52307ddb9deadbae6fd - Sigstore transparency entry: 766358639
- Sigstore integration time:
-
Permalink:
afrotech-panther/braid-formula@55800b4212c03835b08b1e78b061e63082bc82d2 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/afrotech-panther
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@55800b4212c03835b08b1e78b061e63082bc82d2 -
Trigger Event:
release
-
Statement type: