Skip to main content

Dashborg Python SDK

Project description

Dashborg Python SDK

Dashborg is a SDK that plugs directly into any backend service or script. With a couple lines of code you can register any running function with the Dashborg service and then build secure, modern, interactive tools on top of those functions using a simple, JavaScript free, HTML template language.

Dashborg saves you time by handling all of the tedious details of frontend app creation and deployment (hosting, end-to-end security, authentication, transport, UI libraries, JavaScript frameworks, CSS frameworks, etc.).

Dashborg works great for debugging, introspecting the running state of servers, viewing/updating configuration values, bite-sized internal tools, status pages, and reports.

Dashborg is easy to get started with. You can have your first app deployed in 5-minutes (no account/registration required). Free tier covers most simple use cases.

Questions? Join the Dashborg Slack Channel

Dashborg Hello World

pip install dashborg-python-sdk
import dashborg
import asyncio

counter = 0

def test_fn():
    global counter
    counter += 1
    print(f"Calling TestFn counter={counter}")
    return {"message": "TestFn Output!", "counter": counter}

async def main():
    config = dashborg.Config(anon_acc=True, auto_keygen=True)
    client = await dashborg.connect_client(config)
    app = client.app_client().new_app("hello-world")
    app.set_html(file_name="hello-world.html", watch=True)
    app.runtime.handler("test-handler", test_fn, pure_handler=True)
    await client.app_client().write_app(app, connect=True)
    await client.wait_for_shutdown()

asyncio.run(main())

The HTML template to render your app (save as hello-world.html):

<app ui="dashborg">
  <h1>Hello World</h1>
  <div class="row xcenter">
    <d-button onclickhandler="$.output = /@app:test-handler">Run Test Handler</d-button>
    <d-stat label="Counter" bind="$.output.counter" defaultvalue="0"/>
  </div>
  <hr/>
  <d-dataview bind="$.output"/>
</app>

Run your program. A new public/private keypair will be created and used to secure your new Dashborg account. You'll also see a secure link to your new application. Click to view your application!

That's it. You've created and deployed, secure, interactive web-app that is directly calling code running on your local machine!

Adding BLOBs

Want to show an image, or add a CSV file your end users to download, here's how to do it:

    await client.global_fs_client().set_static_path("/image/myimage.jpg", file_name="./path-to-image.jpg", fileopts=dashborg.FileOpts(mimetype="image/jpeg"))
    await client.global_fs_client().set_static_path("/mydata.csv", file_name="./path-to-csv.csv", fileopts=dashborg.FileOpts(mimetype="text/csv"))

Show the image using a regular <img> tag in your HTML template. Using the path prefix "/@raw/" allows for raw http GET access to your uploaded content:

    <img src="/@raw/image/myimage.jpg" style="max-width: 500px;"/>

Download the CSV using a standard HTML download link:

    <a href="/@raw/mydata.csv" download>Download CSV</a>

Or use a Dashborg download control (defined in the standard Dashborg UI package) to make it look nice:

    <d-download path="/mydata.csv">Download CSV</d-download>

Adding Static Data

Dashborg uses JSON to transfer data between your app and the Dashborg service. You can send any static JSON-compatible data (bool, str, int, float, dict, list) to Dashborg using set_json_path(). Static data is available to apps even when there is no backend connected. For dynamic data, use a runtime handler. Here we'll set favorite color table to the path "/colors.json". We used the app_fs_client() instead of the global_fs_client(). That makes the data local to the app and is accessible at /@app/colors.json:

colors = []
colors.append({"name": "Mike", "color": "blue", "hex": "#007fff"})
colors.append({"name": "Chris", "color": "red", "hex": "#ee0000"})
colors.append({"name": "Jenny", "color": "purple", "hex": "#a020f0"})
await app.app_fs_client().set_json_path("/colors.json", colors)

Load the data into our datamodel using the <d-data> tag. Read from blob "colors", set it into the frontend data model at $.colors:

<d-data query="/@app/colors.json" output.bindpath="$.colors"/>

Show the first color name as text using <d-text>. Use the hex color to show a small color square using a background-color style (attributes and styles are dynamic when they starts with *):

<div>
    <d-text bind="$.colors[0].name"/>'s favorite color is <d-text bind="$.colors[0].color"/>:
    <div style="display: inline-block; vertical-align: bottom; width: 18px; height: 18px; background-color: *$.colors[0].hex"/>
</div>

You can loop using the built-in <d-foreach> tag (each element is bound to . inside the loop):

<ul class="ui bulleted list">
    <d-foreach bind="$.colors">
      <li class="item" style="height: 24px">
        <div class="row">
          <div><d-text bind=".name"/> - Favorite Color is <d-text bind=".color"/></div>
          <div style="width: 18px; height: 18px; background-color: * .hex"/>
        </div>
      </li>
    </d-foreach>
</ul>

Or use a Dashborg Table Control (@index is bound to the loop counter):

<d-table bind="$.colors">
   <d-col label="#" bind="@index+1"/>
   <d-col label="Name" bind=".name"/>
   <d-col label="Color" bind=".color"/>
   <d-col label="Swatch">
       <div style="width: 50px; height: 50px; background-color: * .hex"/>
   </d-col>
</d-table>

Security

All communication from your backend to the Dashborg service is done over HTTPS/gRPC. Your account is authenticated with a public/private keypair that can be auto-generated by the Dashborg SDK (AutoKeygen config setting).

The frontend is served over HTTPS, and each account is hosted on its own subdomain to prevent inter-account XSS attacks The Dashborg frontend offers pre-built authentication methods, with JWT tokens that are created from your private-key (the default for new anonymous accounts), simple passwords, or user logins.

Advanced Features

  • Write your own Dashborg components to reuse among your applications
  • Create staging/development zones to test your apps without affecting your production site
  • Assign roles to users (and passwords), set a list of allowed roles per app per zone
  • Navigate to the '/@fs' path on your Dashborg account to see all of your static data, applications, and handlers.

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

dashborg-python-sdk-0.4.0.dev2.tar.gz (29.9 kB view details)

Uploaded Source

Built Distribution

dashborg_python_sdk-0.4.0.dev2-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file dashborg-python-sdk-0.4.0.dev2.tar.gz.

File metadata

  • Download URL: dashborg-python-sdk-0.4.0.dev2.tar.gz
  • Upload date:
  • Size: 29.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0

File hashes

Hashes for dashborg-python-sdk-0.4.0.dev2.tar.gz
Algorithm Hash digest
SHA256 b410398798f94e908573125698d95c77256e63bca5ae372031bd4a82a8e49d67
MD5 fe6a7f165822036537f82d0fff53e347
BLAKE2b-256 a7207d82ae028853c1b1f2006354e958f0271fd0fc4dc74adad1d29756651c76

See more details on using hashes here.

File details

Details for the file dashborg_python_sdk-0.4.0.dev2-py3-none-any.whl.

File metadata

  • Download URL: dashborg_python_sdk-0.4.0.dev2-py3-none-any.whl
  • Upload date:
  • Size: 27.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0

File hashes

Hashes for dashborg_python_sdk-0.4.0.dev2-py3-none-any.whl
Algorithm Hash digest
SHA256 941e9d2866270a932437c59d620115afcee0aa0640740c8dde6274b3b9402f0d
MD5 5204784586a33e51e0cf5a5940415739
BLAKE2b-256 005a573ae91e76c3cfcb719ab5cb39c5306f6551da7964fabb517b3663d6a2ca

See more details on using hashes here.

Supported by

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