Skip to main content

Cross-platform cannabis math library for potency, dosing, pricing, taxes, rounding, and retail calculations.

Project description

CannabisMath

.NET NuGet NPM PyPI Tests License

CannabisMath is a cross-platform cannabis calculation library for potency, dosing, weight conversions, pricing, packaging, taxes, rounding, and retail value calculations.

Built for cannabis apps, dashboards, dispensary tooling, POS workflows, inventory systems, calculators, and data projects.

Reliable weed math. Tested, reusable, and consistent across languages.


Status

Current version: v0.1.0

  • C# library published to NuGet
  • TypeScript port complete (in /js)
  • Full parity between C# and JS logic
  • 130+ combined tests across both implementations

Quick Start (C#)

using CannabisMath.Core.Composites;

var pricePerMg = CannabisValueCalculator.PricePerMgFromWeightAndPotency(
    price: 35m,
    weightGrams: 3.5m,
    potencyPercent: 20m
);
// 0.05

Quick Start (TypeScript)

import { CannabisValueCalculator } from "./js/src/composites/cannabisValueCalculator";

const result = CannabisValueCalculator.pricePerMgFromWeightAndPotency(
  35,
  3.5,
  20
);
// 0.05

Why CannabisMath?

Cannabis calculations are often inconsistent across apps, dashboards, and POS systems. Differences in rounding, weight assumptions, potency formulas, and tax handling can lead to mismatched results and operational issues.

CannabisMath provides a single, deterministic calculation layer to ensure consistent results across systems and languages.


Cross-Language Consistency

This project maintains identical calculation logic across:

  • C# (.NET / NuGet)
  • TypeScript (Node / Web)

Same inputs → same outputs → everywhere.


Project Structure

CannabisMath/
  src/ (C# core library)
  tests/ (C# tests)

  js/
    src/ (TypeScript implementation)
    tests/ (Vitest)

Installation

C#

dotnet add package CannabisMath.Core

TypeScript (coming soon to NPM)

npm install cannabismath

Test Coverage

  • C#: 68 tests
  • TypeScript: 64 tests

Total: 130+ passing tests


Roadmap

  • NPM package publish
  • Python port
  • Shared cross-language test fixtures
  • Jurisdiction-aware tax configs
  • POS rounding strategies
  • Advanced pricing & margin tools

Disclaimer

CannabisMath is a calculation library, not legal or tax advice.


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cannabismath-0.1.1.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cannabismath-0.1.1-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file cannabismath-0.1.1.tar.gz.

File metadata

  • Download URL: cannabismath-0.1.1.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for cannabismath-0.1.1.tar.gz
Algorithm Hash digest
SHA256 60b6ff5f01b2df25be29514bdd65a2d9005cb6adc7b5f03295376b16a13ee802
MD5 282a4a5906e4ecee592c37c5bb2a110b
BLAKE2b-256 b7685c738501e820cc4de4e8bb9726e749c64431fa727038e78a8d1a5456e1ea

See more details on using hashes here.

File details

Details for the file cannabismath-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cannabismath-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for cannabismath-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1e57645877944ad42dc5383c8c74f5f44e53cc504f100c13e5f4b317c596edaf
MD5 06316de03b5d7383edf5b71312f2c64c
BLAKE2b-256 7e50301bc5ecf9e2459cf9089326a516168c6d439514279d66cf3495ee54492e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page