Skip to main content

Multidimensional Data Structures for Python.

Project description

PyCells logo

pycells_mds

Multidimensional Data Structures


🔍 Overview

PyCells MDS is a Python library for spreadsheet-like multidimensional data structures with hierarchical addressing.
It supports Excel-style formulas, programmable cells, cell groups, hierarchical cell_id, JSON export, and a full Python API.

PyCells can be used to build accounting systems, warehouse structures, CRM/ERP modules, and dynamic spreadsheet engines.


✨ Features

  • Tables and sheets
  • Named cells (A1, B2, …)
  • Hierarchical cell_id (e.g. 0000.0001.0001.0003)
  • Automatic recalculation engine
  • Excel-style formulas
  • Ranges (A1:A10)
  • Built-in function set (SUM, IF, UPPER, etc.)
  • Cell groups
  • Notes and styles
  • JSON / FLAT / TREE export
  • Select queries
  • Cursor manager (Redis + SQL optional)
  • SQLite / PostgreSQL support

🛠 Installation

pip install pycells_mds

Requirements

Python 3.9+

SQLAlchemy

NumPy

Redis (optional, CursorManager)

🚀 Quick Start

1) Initialize database

from pycells_mds.session import init_db
from pycells_mds.core import PyCells

init_db({
    "engine": "sqlite",
    "path": "my_cells.db"
})

pc = PyCells()
print("Database connected.")

2) Register user

user = pc.safe_register_user("user1", "pw123", "user1@example.com")
user_id = user.id

3) Create table and sheet

tbl = pc.ctable("Finance", user_id)
sheet = pc.get_or_create_list("Finance", "Main", user_id)

🔢 Writing and Reading Cells

New API (with hierarchical cell_id)

pc.write(
    table="Finance",
    sheet="Main",
    cell_name="A1",
    cell_id="0000.0001.0001.0001",
    data="100",
    user_id=user_id
)

pc.write("Finance", "Main", "A2", "0000.0001.0001.0002", "200", user_id)
pc.write("Finance", "Main", "A3", "0000.0001.0001.0003", "=A1+A2", user_id)

print(pc.read("Finance", "Main", "A3", user_id))


# → 300.0

Read with full cell info

value = pc.read("Finance", "Main", "A1", user_id)

# returns dict:
# { "name": "A1", "value": "100", "data": "100", "cell_id": "0000.0001.0001.0001" }

📦 Export

JSON export (dictionary)

json_data = pc.export("Finance", "Main", mode="json", user_id=user_id)

print(json_data)

Result:

{
    "A1": {"id": 1, "name": "A1", "value": "100", "data": "100", "cell_id": "0000.0001.0001.0001"},
    "A2": {...}
}

FLAT export (list)

flat = pc.export("Finance", "Main", mode="flat", user_id=user_id)

Example:

[
    {"id": 1, "name": "A1", ...},
    {"id": 2, "name": "A2", ...}
]

TREE export (hierarchical by cell_id)

tree = pc.export_tree("Finance", "Main", user_id)

Example:

{
  "0000": {
    "0001": {
      "0001": {
        "0001": {...},
        "0002": {...}
      }
    }
  }
}

🔢 Formulas

Supported operators


( + ) , ( - ) , ( * ) , ( / ) , ( ^ ) , ( % )


Supported constructs

  • ranges (A1:A10)

  • nested formulas

  • built-in functions

  • SUM, MAX, MIN, AVERAGE

  • ABS, ROUND, POWER

  • INT, VALUE

  • UPPER, LOWER, CONCAT, TEXTJOIN

  • IF

  • TODAY, NOW, DATE, YEAR, MONTH, DAY

  • TEXT

  • ETEXT — Exel notation text

  • np.* — NumPy access for ranges

Example:

pc.write("Finance", "Main", "B1", "=SUM(A1:A3)", user_id)
pc.write("Finance", "Main", "B2", "=A1^A2", user_id)

🎯 Groups

Create group

sheet.add_group("Totals", ["A1", "A2", "A3"], style="color:red;")

Get group cells

cells = sheet.get_group_cells("Totals")
print([c.name for c in cells])

Update style

sheet.update_group_style("Totals", "background:yellow;")

Delete group

sheet.delete_group("Totals")

🖱 CursorManager (optional)

from pycells_mds.managers import CursorManager

CursorManager.set_cursor(
    user_id=user_id,
    table_id=sheet.model.table_id,
    list_id=sheet.model.id,
    cells=["A1", "A2"]
)

CursorManager.get_active(user_id)

🔄 Recalculation

pc.recalc("Finance", "Main", user_id)
📄 Select cells

result = pc.select("Finance", "Main", "A1", "A3", "C1", user_id=user_id)

Returns:

{
  "A1": {"name": "A1", "value": "100", ...},
  "A3": {...},
  "C1": {...}
}

🌐 Backup / Restore

Backup (JSON)

data = pc.export("Finance", "Main", "json", user_id)

Restore

for name, c in data.items():
    pc.write("Finance", "Main", name, c["cell_id"], c["data"], user_id)

📡 FastAPI Integration

PyCells works perfectly as a backend engine behind FastAPI.

Typical endpoints:

  • /write

  • /read

  • /export/json

  • /export/tree

  • /recalc

🧩 Use Cases

  • Accounting structures (plan of accounts)

  • Warehouse hierarchy

  • Financial models

  • CRM/ERP spreadsheets

  • Document engines

  • Structured multidimensional data

📜 License

  • Versions < 1.0.0 are licensed under the MIT License
  • Versions >= 1.0.0 are distributed under a commercial license

📞 Contact

Email: zhandos.mambetali@gmail.com

WhatsApp: +7 701 457 7360


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

pycells_mds-0.2.91.tar.gz (141.9 kB view details)

Uploaded Source

Built Distribution

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

pycells_mds-0.2.91-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file pycells_mds-0.2.91.tar.gz.

File metadata

  • Download URL: pycells_mds-0.2.91.tar.gz
  • Upload date:
  • Size: 141.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for pycells_mds-0.2.91.tar.gz
Algorithm Hash digest
SHA256 b640f34c4f1f9344c92de0f8fbf6ed7edb48e175daa105454b45e2a7a1737805
MD5 247d627eefca70cbf74ebf62f49a814f
BLAKE2b-256 d28b5524fdcafa56a0161f8f2fe396e47f222bd0e7b766cf5594b19d07ce4ad5

See more details on using hashes here.

File details

Details for the file pycells_mds-0.2.91-py3-none-any.whl.

File metadata

  • Download URL: pycells_mds-0.2.91-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for pycells_mds-0.2.91-py3-none-any.whl
Algorithm Hash digest
SHA256 25955ef6027a6fb67bf0ae3da78936a8a4b3f44e1a8906d8c5ae419954383d88
MD5 51615654b0c6627220dbd090902feadb
BLAKE2b-256 72863660128087579d0f413f024b77afac759e7e94734ebef90ae653353161d0

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