Skip to main content

Easily create data visualization of static or streaming data

Project description

Easily create data visualization of static or streaming data

Get Started

pip install easycharts

Create EasyCharts Server

# charts.py
from fastapi import FastAPI
from easycharts import ChartServer

server = FastAPI()

@server.on_event('startup')
async def setup():
    server.charts = await ChartServer.create(
        server,
        charts_db="test"
    )

    await server.charts.create_dataset(
        "test",
        labels=['a', 'b', 'c', 'd'],
        dataset=[1,2,3,4]
    )

Start Server

uvicorn --host 0.0.0.0 --port 0.0.0.0 charts:server

Update Data via API

In a separate window, access the OpenAPI docs to demonstrate dynanimc updates to the graph

http://0.0.0.0:8220/docs

Line

Bar

APIS

Real World Usage - Resource Monitoring

import datetime, psutil
import asyncio
from fastapi import FastAPI
from easycharts import ChartServer
from easyschedule import EasyScheduler

scheduler = EasyScheduler()
server = FastAPI()

every_minute = '* * * * *'

@server.on_event('startup')
async def setup():
    asyncio.create_task(scheduler.start())
    server.charts = await ChartServer.create(
        server,
        charts_db="charts_database",
        chart_prefix = '/mycharts'
    )

    await server.charts.create_dataset(
        "test",
        labels=['a', 'b', 'c', 'd'],
        dataset=[1,2,3,4]
    )

    # set initial sync time
    label=datetime.datetime.now().isoformat()[11:19]
    await server.charts.create_dataset(
        'cpu',
        labels=[label],
        dataset=[psutil.cpu_percent()]
    )
    await server.charts.create_dataset(
        'mem',
        labels=[label],
        dataset=[psutil.virtual_memory().percent]
    )

    @scheduler(schedule=every_minute)
    async def resource_monitor():
        time_now=datetime.datetime.now().isoformat()[11:19]

        # updates CPU & MEM datasets with current time
        await server.charts.update_dataset(
            'cpu',
            label=time_now,
            data=psutil.cpu_percent()
        )
        await server.charts.update_dataset(
            'mem',
            label=time_now,
            data=psutil.virtual_memory().percent
        )

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

easycharts-0.106-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file easycharts-0.106-py3-none-any.whl.

File metadata

  • Download URL: easycharts-0.106-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for easycharts-0.106-py3-none-any.whl
Algorithm Hash digest
SHA256 ab90d2bd1b55f9d159a18ed3e2a5b9d4be2a9449ba83d545300e28f22ac3fb0b
MD5 060fb49c7f1401546e947a3dc16ffc4a
BLAKE2b-256 14652a5d51d4e5132857aa4bd1913fff934a21128a02a270d6a31adfac8c293f

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