v-macrev / flaskapi-azureconnection

This script is a Flask web application that acts as a simple API for executing SQL queries on an Azure Synapse SQL database. It exposes a single API endpoint (/query) that accepts POST requests with a JSON payload containing a 'query' key, and it returns the results of the executed SQL query in JSON format.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flask Web App API for Azure Synapse SQL Database

This script is a Flask web application that acts as a simple API for executing SQL queries on an Azure Synapse SQL database. It exposes a single API endpoint (/query) that accepts POST requests with a JSON payload containing a 'query' key, and it returns the results of the executed SQL query in JSON format. The application uses the pyodbc library to connect to the Azure Synapse SQL database and the pandas library to convert query results into a JSON-friendly format. It's a basic example and should be extended with security measures and additional features for a production environment.

Getting Started

Prerequisites

Setup

  1. Clone the repository:

    git clone https://github.com/v-macrev/flaskapi-azureconnection.git
  2. Navigate to the project directory:

    cd flaskapi-azureconnection
  3. Create and activate a virtual environment:

    python -m venv apienv
    source apienv/bin/activate   # For Unix/Linux
    # or
    .\apienv\Scripts\activate    # For Windows
  4. Install the required dependencies:

    pip install -r requirements.txt

Usage

  1. Start the Flask web application:

    flask run

or

python main.py
  1. Open your favorite API testing tool, such as Postman or use the provided test.http file.

  2. Send sample requests to the API to execute SQL queries on the Azure Synapse SQL database.

Testing with test.http

For your convenience, I've included a test.http file that contains sample HTTP requests to test various endpoints of the API. You can use this file with an extension like REST Client in Visual Studio Code or other similar tools.

Contributing

If you encounter any issues or have suggestions for improvement, feel free to open an issue or submit a pull request.

Happy coding!

About

This script is a Flask web application that acts as a simple API for executing SQL queries on an Azure Synapse SQL database. It exposes a single API endpoint (/query) that accepts POST requests with a JSON payload containing a 'query' key, and it returns the results of the executed SQL query in JSON format.

License:MIT License


Languages

Language:Python 100.0%