Creating a Python web app

David Thielen 3,191 Reputation points
2024-08-13T01:30:26.4266667+00:00

Hi;

This is likely a very basic question. There are two of us. I know writing ASP.NET and Blazor web apps and publishing them to Azure App Service. The other developer knows Python. And in the lack between our skill sets is this question.

We need to create a web app, written in Python, running on Azure App Server, that has an API that will be called by my Blazor app. My app is the only app that will call this (if we could mix Python and C# code we would just make this part of the Blazor app).

So...

  1. Can a Python web app be created in Visual Studio?
  2. What needs to be done to provide a callable API in it? Hopefully something like ASP.NET where the controllers have attributes declaring the public API.
  3. Can we configure these two app servers in Azure so this app can only be called by the Blazor app? That way it's a "public" API with no need to handle authentication/authorization.
  4. Am I missing anything?

thanks - dave

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,500 questions
0 comments No comments
{count} votes

Accepted answer
  1. Vlad Costa 1,480 Reputation points
    2024-08-13T01:53:03.72+00:00

    Hi @David Thielen

    Your questions are quite relevant, and I will try to answer them for you.

    1. Can a Python web app be created in Visual Studio? Yes, you can create a Python web app in Visual Studio. Visual Studio supports Python development through the Python Development workload. You can use frameworks like Flask or Django to build your web app.
    2. What needs to be done to provide a callable API in it? You can use Flask or Django REST framework to create a callable API in your Python web app. These frameworks allow you to define routes and endpoints similar to ASP.NET controllers. For example, in Flask, you can use decorators to define your API endpoints:
         from flask import Flask, jsonify
         app = Flask(__name__)
         @app.route('/api/data', methods=['GET'])
         def get_data():
             return jsonify({'key': 'value'})
         if __name__ == '__main__':
             app.run()
      
    3. Can we configure these two app servers in Azure so this app can only be called by the Blazor app? Yes, you can configure your Azure App Services to restrict access. One way to achieve this is by using Azure API Management or configuring IP restrictions. You can whitelist the IP address of your Blazor app’s server so that only requests from this IP are allowed.
    4. Am I missing anything? Ensure that your Python web app is properly secured, even if it’s only being called by your Blazor app. Consider using HTTPS and validating incoming requests. Additionally, if your Blazor app and Python API are hosted on different domains, you might want to handle potential cross-origin resource sharing (CORS) issues.

    If this answers your question, please click Accept Answer and Yes if this answer was helpful. Doing so would help other community members with similar issues identify the solution. I highly appreciate your contribution to the community.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.