Cross-platform cannabis math library for potency, dosing, pricing, taxes, rounding, and retail calculations.
Project description
CannabisMath (Python)
CannabisMath is a cross-platform cannabis calculation library designed for accuracy, consistency, and real-world retail use.
This Python package provides deterministic calculations for:
- Potency (THC / CBD from COA values)
- Dosing (mg calculations)
- Weight conversions (grams, ounces, pounds)
- Pricing (price per gram / mg)
- Taxes
- Rounding (including POS-safe nickel rounding)
- Packaging and retail breakdowns
- Composite value calculations
Installation
pip install cannabismath
Quick Start
from cannabismath import PotencyCalculator
total_thc = PotencyCalculator.calculate_total_thc(1.2, 24.8) print(total_thc) # 22.9496
Why CannabisMath?
Cannabis calculations are often inconsistent across apps, dashboards, and POS systems.
Differences in:
- rounding rules
- weight assumptions
- potency formulas
- tax handling
can lead to mismatched results and real operational issues.
CannabisMath provides a single, deterministic calculation layer to ensure consistent results across systems and languages.
Cross-Platform Design
CannabisMath is designed to produce identical results across:
- C# (NuGet)
- TypeScript (NPM)
- Python (PyPI)
All implementations share the same test fixtures to guarantee parity.
Example: Dosing
from cannabismath import DoseCalculator
total_mg = DoseCalculator.total_mg_from_percent(3.5, 20) print(total_mg) # 700
Example: Rounding
from cannabismath import RoundingCalculator
rounded = RoundingCalculator.round_cash_to_nearest_nickel(10.03) print(rounded) # 10.05
Test Integrity
CannabisMath uses shared JSON test fixtures across all languages to ensure:
- consistent outputs
- no drift between implementations
- predictable results for real-world usage
Use Cases
- Dispensary POS systems
- Cannabis analytics dashboards
- Inventory and pricing tools
- Data pipelines and automation scripts
- Consumer-facing calculators
Disclaimer
CannabisMath is a calculation library only.
It is not legal, tax, medical, or compliance advice.
Always verify calculations against local regulations.
License
MIT
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 cannabismath-0.1.2.tar.gz.
File metadata
- Download URL: cannabismath-0.1.2.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9effc679bc1e7a9e1f126e50df4cc799712cb29cf576f5bfe358db637005b06
|
|
| MD5 |
38cf38c0a89aa8de708a11086590c43c
|
|
| BLAKE2b-256 |
a86437b0e85d281b15113ae1ab93637eb3ab05aca26964db236b40e0a091f72c
|
File details
Details for the file cannabismath-0.1.2-py3-none-any.whl.
File metadata
- Download URL: cannabismath-0.1.2-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a3fdb2ceb21ac5558cbabe1a49e0d7ec75e50575499d97e6907ed6be5181db9
|
|
| MD5 |
d4b53d0fe4b4cb67f7ad76a6f3ad6a85
|
|
| BLAKE2b-256 |
ef7c86067441be6aea1c6b8d7b31bf60dc3c483cb4eba14290bf65045f176d1a
|