Skip to main content

Flow Python Client

Introducing the Flow Immersive Python Client – a convenient solution for pushing data from pandas to Flow. With this library, you can easily upload datasets and identify them using a unique title. If you upload a new dataset with the same title, it will create a new version of the same dataset.

Here's how to use it.

Import the necessary libraries:

import pandas as pd
from flowgl import Client

The flowgl pip contains the code necessary to interact with the Flow API to push data to Flow, where it will appear in the "Dataset" item within the user interface:

image.png

Any dataset uploaded via the API will appear in the UI under Managed Data -> Data upload.

In the example above, the "airports" dataset was uploaded on February 16, and a version is identified for that date.

The Flow can be told to "Keep up with latest version" instead of referencing a specific version of the dataset. Keep the box unchecked if the Flow is used for a presentation where it could be problematic to have data changing outside of the Flow, say you work on it on Friday for a presentation Monday, yet you or someone on your team happens to update the data over the weekend, you might have a surprise in front of your audience with different data. 

On the other hand, you might want the Flow to be continually updated with the latest dataset, like the weather, and you'll want to select the checkbox.

Create a sample pandas dataframe:

Back to the python script, work with your dataframe as you wish.

df = pd.DataFrame({
    'name': ['John', 'Jane', 'Joe'],
    'age': [30, 25, 40],
    'city': ['New York', 'San Francisco', 'Los Angeles']
})

Create an instance of the client with your Flow credentials:

client = Client(
    username=...,
    password=...,
)

Push the dataframe to Flow by defining a title:

client.push_data(
    df,
    dataset_title='My Dataset',
)

If the title doesn't yet exist for your user, a dataset will be created. If the title exists, a new version will be created.

 

If you are working with Network Graph datasets, and have a dictionary of nodes and edges, you can use the push_nodes_and_edges_dict method. This method requiresdescribed youhere: to specify the nodes and edges lists in the provided dictionary using jsonpath. Here's an example:https://docs.flow.gl/books/flow-documentation/page/network-graph-uploading-nodes-and-edges-with-python-and-flow-api.

my_dict = {
    'nested_object': {
        'nodes': [
            {'key': 1, 'name': 'John'},
            {'key': 2, 'name': 'Jane'},
            {'key': 3, 'name': 'Joe'},
        ],
        'edges': [
            {'src': 1, 'dest': 2},
            {'src': 2, 'dest': 3},
        ]
    }
}

client.push_nodes_and_edges_dict(
    my_dict,
    nodes_jsonpath='$.nested_object.nodes',
    edges_jsonpath='$.nested_object.edges',
    node_id_key='key',
    edge_source_key='src',
    edge_target_key='dest',
    dataset_title='My Dataset',
)

With the Flow Immersive Python Client, it's easier than ever to push data from pandas to Flow, whether it be in the form of a pandas DataFrame or a dictionary of nodes and edges. With its user-friendly methods, you can quickly and easily upload your data to Flow, identify it with a title, and create new dataset versions if needed.Flow. The code examples provided in this blog post give you a good starting point for using the Flow Immersive Python Client in your own projects.

In conclusion, the Flow Immersive Python Client offers a simple and efficient solution for pushing data from pandas to Flow, making it a valuable tool for anyone looking to streamline their data management process.

See also: Data Transformation with Orange and Alteryx