Git Product home page Git Product logo

azure-python-siteextensions's Introduction

Azure Python Site Extensions

This repository contains the build scripts for the Python site extensions for Azure App Service.

Installing and Using

To install a Site Extension into an Azure App service instance, you can use the portal at portal.azure.com. Go to the Web App and search for Extensions.

To deploy as part of an ARM template, include a site extension resource in your site. For example, the below resource will install Python 3.6.4 x64 as part of deploying your site.

{
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('siteName')]",
      "type": "Microsoft.Web/sites",
      ...
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "azureappservice-python364x64",
          "type": "siteextensions",
          "properties": { },
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('siteName'))]"
          ]
        },
      ...

Once the site extension has been installed, you need to activate Python through your web.config file using either the FastCGI module or the HttpPlatform module.

Using FastCGI

The wfastcgi package is preinstalled and configured as part of the extension. This module uses the IIS FastCGI module to communicate with a persistent Python process that has provided a WSGI-compatible web server.

Your web.config configuration should include the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
    <add key="WSGI_HANDLER" value="app.wsgi_app"/>
    <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
  </appSettings>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python364x64\python.exe|D:\home\python364x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
    </handlers>
  </system.webServer>
</configuration>

The value for PYTHONPATH may be freely extended, but must include the root of your website. WSGI_HANDLER should be updated to point to a WSGI app importable from your website. WSGI_LOG is optional but recommended while debugging your site. All app settings are made available to the app as environment variables.

The path to python.exe may need to be customized depending on the version of Python you are using. See the description of the site extension to find out where it will be installed and update these paths accordingly.

Using HttpPlatform

The HttpPlatform module forwards socket connections directly to a standalone Python process, so you will require a startup script that runs a local web server.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath="D:\home\python364x64\python.exe"
                  arguments="D:\home\site\wwwroot\runserver.py --port %HTTP_PLATFORM_PORT%"
                  stdoutLogEnabled="true"
                  stdoutLogFile="D:\home\LogFiles\python.log"
                  startupTimeLimit="60"
                  processesPerApplication="16">
      <environmentVariables>
        <environmentVariable name="SERVER_PORT" value="%HTTP_PLATFORM_PORT%" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>

The path to python.exe may need to be customized depending on the version of Python you are using. See the description of the site extension to find out where it will be installed and update these paths accordingly.

Arguments may be freely customized for your app. The HTTP_PLATFORM_PORT environment variable contains the port your local server should listen on for connections from localhost.

In this example, another environment variable SERVER_PORT is created, but this is not required. Environment variables may be added or removed as necessary for your app.

Static Files

For static directories, we recommend using another web.config to remove the Python handler and allow the default static file handler to take over. Such a static/web.config may look like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <remove name="PythonHandler" />
    </handlers>
  </system.webServer>
</configuration>

Contributing

Contributions are welcomed to this repository. Updates to official site extensions are managed by Microsoft employees. If you do intend to publish your own extensions built from these scripts, please modify the nuspec files to avoid confusion.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Building the extensions

To build all extensions, run build_all.cmd.

To build one extension, use build.cmd [source Nuget package] [version] [package name], where source Nuget package is the name of the official Nuget release to base the extension on, version is the version of , and package name is both the name of the subdirectory with the .nuspec file and other content and the suffix for the release.

For example:

build.bat python 3.6.4 362x64
build.bat python2 2.7.14 2714x86

License

Licensed as MIT - please see LICENSE for details.

azure-python-siteextensions's People

Contributors

davidebbo avatar zooba avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.