Skip to main content

Library to build Gloodata extensions

Project description

Glootil

A Python 3 library to create gloodata extensions.

Usage

mkdir my-gd-ext
cd my-gd-ext
uv init
uv add glootil uvicorn fastapi

edit main.py to contain:

from datetime import datetime
from enum import Enum

from glootil import Toolbox

tb = Toolbox("my-gd-ext", "My Extension", "My Utility Tools")


@tb.enum(icon="visible")
class DisplayFormat(Enum):
    LINE = "Line"
    TABLE = "Table"
    TEXT = "Text"


@tb.tool(
    name="Compound Interest Rate Calculator",
    ui_prefix="Compound Interest Rate",
    args={
        "principal": "Principal",
        "interest_rate": "Interest Rate",
        "years": "Years",
        "display_format": "Format",
    },
    examples=[
        "calculate compound interest for initial 1500 dollars, 2.5% interests for 8 years in line chart",
        "compound interst for $2000 at 3.5% interests for 10 years as a table",
    ],
)
def compound_interest_calculator(
    principal: float = 1.0,
    interest_rate: float = 3.0,
    years: int = 5,
    display_format: DisplayFormat = DisplayFormat.LINE,
):
    year = datetime.now().year
    amount = principal
    cols = [("year", "Year"), ("amount", "Amount"), ("interest", "Interest")]
    rows = []

    for i in range(0, years + 1):
        interest = amount * (interest_rate / 100)
        rows.append((year + i, amount, interest))
        amount += interest

    if display_format == DisplayFormat.TABLE:
        return {
            "type": "Table",
            "columns": cols,
            "rows": rows,
        }
    elif display_format == DisplayFormat.TEXT:
        lines = [
            f"- {year}: ${amount} (${interest} interests)"
            for (year, amount, interest) in rows
        ]
        return "\n".join(lines)
    else:
        return {
            "type": "Series",
            "title": "Compound Interest by Year",
            "xColTitle": "Year",
            "yColTitle": "$",
            "xCol": "year",
            "valCols": ["amount", "interest"],
            "cols": cols,
            "rows": rows,
        }


tb.serve(host="127.0.0.1", port=8087)

Start:

uv run main.py

On gloodata write in the prompt bar:

Add extension Fincance at port 8087

Click Test and then Save

Now in the prompt bar write something like:

calculate compound interest for initial 2500 dollars, 3.5% interests for 15 years

Check the examples folder for more.

License

MIT, see LICENSE file for details

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

glootil-0.2.0.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

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

glootil-0.2.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file glootil-0.2.0.tar.gz.

File metadata

  • Download URL: glootil-0.2.0.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.16

File hashes

Hashes for glootil-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d350386f503521e2695cd49ea82a4dd6c908f20f6afa10553f9f8b2b6ee55413
MD5 592ddc62963272f76a23ffb736b95976
BLAKE2b-256 4a4f92d68af3cf1f77919006d75eccc38c8e431171e4e785909d1e9fb0923c5a

See more details on using hashes here.

File details

Details for the file glootil-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: glootil-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.16

File hashes

Hashes for glootil-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a31987dbdb00c7feff5de6f15c3b6f7df82da41b844c44ae9bccf932a0aadf54
MD5 742b491f3982e107e59bdf86f0a5c178
BLAKE2b-256 71cb618ad5d82fc9c3bd372abb085967c7c501480d10686edf5bdd0eb2ff4021

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