Skip to content

XpressAI/xai-flask

Repository files navigation

Component LibrariesProject Templates
DocsInstallTutorialsDeveloper GuidesContributeBlogDiscord

Xircuits Component Library for Flask! Simplify building and managing web applications with seamless integration.


Xircuits Component Library for Flask

A comprehensive suite of components designed for creating and managing web applications using Flask within the Xircuits environment.

Table of Contents

Preview

InlineExample

InlineExample

InlineExample Result

InlineExample_result

DeclarativeExample

DeclarativeExample

DeclarativeExample Result

DeclarativeExample_result py

Prerequisites

Before you begin, you will need the following:

  1. Python3.9+.
  2. Xircuits.

Main Xircuits Components

FlaskCreateApp Component:

Initializes a Flask application, allowing customization of public paths, static URL paths, and secret key settings for enhanced flexibility.

FlaskCreateApp

FlaskStartServer Component:

Starts the Flask application server, with options to configure debug mode, host address, and port number.

FlaskStartServer

FlaskDefineGetRoute Component:

Defines a GET route in the Flask application, linking it to specific actions or components to handle incoming requests.

FlaskDefinePostRoute Component:

Defines a POST route in the Flask application, enabling execution of actions or components when POST requests are received.

FlaskDefinePutRoute Component:

Defines a PUT route in the Flask application, linking it to specific actions or components for handling PUT requests.

FlaskRenderTemplate Component:

Renders dynamic HTML templates with the ability to pass variables for personalized content delivery.

FlaskReturnStringResponse Component:

Sends a plain text response to the client, ideal for returning simple messages or lightweight API data.

FlaskReturnJSONResponse Component:

Returns structured JSON data, making it essential for APIs or applications requiring client-side data parsing.

FlaskRedirect Component:

Redirects users to a different URL, enabling seamless navigation and flow control within the web application.

Try the Examples

We have provided an example workflow to help you get started with the Flask component library. Give it a try and see how you can create custom Flask components for your applications.

InlineExample

This example creates a Flask server using Xircuits, featuring two routes:

  1. POST /echo: Accepts JSON input, processes it, and returns the input as a plain text response.
  2. GET /greet: Returns a JSON response with a greeting message.

It demonstrates inline route definitions and dynamic request handling.

DeclarativeExample

This example sets up a Flask server with multiple routes:

  1. GET /hello/<name>: Displays the path parameter <name> in a structured response.
  2. POST /hello/<name>: Accepts JSON input and returns it as a JSON response.
  3. GET /stream: Streams a response to the client in chunks, demonstrating real-time data streaming.
  4. PUT /<some>/<path>/<parameters>: Processes path parameters and prints them for debugging.
  5. Interval Job: Prints a message every 5 seconds using a background job scheduler.

It showcases both route definitions and advanced Flask features like streaming and scheduled tasks.

Installation

To use this component library, ensure that you have an existing Xircuits setup. You can then install the Flask library using the component library interface, or through the CLI using:

xircuits install flask

You can also install it manually by cloning and installing it:

# base Xircuits directory  
git clone https://github.com/XpressAI/xai-flask xai_components/xai_flask  
pip install -r xai_components/xai_flask/requirements.txt  

About

Flask component library for Xircuits.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages