KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Koolreport in python framework #578

Open Mazmur opened this topic on on Dec 28, 2018 - 2 comments

Mazmur commented on Dec 28, 2018

Dear Koolreport,

How can I use Koolreport in python framework (Django,Flask,etc) ?

Best Regards,

Mazmur

KoolReport commented on Dec 28, 2018

Hi Mazmur,

KoolReport is working on PHP so I am afraid that it is not possible to apply to python language.

Python is very strong for data analysis, may be you can find some good data visualization packages to add on.

I will note your post here if there is chance we could build a framework with the same concept for Python.

Regards,

Karl Wilkens

KoolReport Software Specialist

eMaX commented on Mar 1

Having the same issue here. I assume we'll need to set up a flask app server that then serves python scripts as ajax end points.

Of course you can also just

    $stmt = $this->pdo->prepare($sql);
    $stmt->execute();
    $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
    $jsonInputData = json_encode($data);
    $pythonPath = shell_exec('which python3');  // you'd do that probably only once
    $pythonPath = trim($pythonPath);
    // relative to your index.php:
    $command = "$pythonPath src/Python/something.py " . escapeshellarg($jsonInputData);
    $output = shell_exec($command);
    $result = json_decode($output, true);

Then in Python e.g. using typer

@app.command()
def run(
    input_data    : Optional[str] = typer.Argument(None, help="Input JSON data as a string"),
) -> None:
    data = json.loads(input_data)
    # do something and generate a df
    output_data = df.to_json(orient='records', date_format='iso')
    print(output_data)

But that means you're going to start a python interpreter each time you do a request. Yes, it works, but then

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
suggestion

None