GithubHelp home page GithubHelp logo

gnat / caddy-snake Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mliezun/caddy-snake

0.0 1.0 0.0 45 KB

Caddy plugin that gives native support for Python WSGI apps.

License: MIT License

C 67.09% Go 32.91%

caddy-snake's Introduction

Caddy Snake ๐Ÿ

Caddy plugin that gives native support for Python WSGI apps.

It embeds the Python interpreter inside Caddy and serves requests directly without going through a reverse proxy or creating a new process.

Install

Go 1.21 and Python 3.12 or later is required, with development files to embed the interpreter.

To install Python3.12 in Ubuntu do:

apt-get install -y software-properties-common
add-apt-repository ppa:deadsnakes/ppa
apt-get install -y python3.12-dev

To install in MacOS do:

brew install [email protected]

Bundling with Caddy

Build this module with caddy at Caddy's official download site. Or:

CGO_ENABLED=1 xcaddy build --with github.com/mliezun/caddy-snake

Use Docker to build

Dockerfile:

FROM python:3.12

WORKDIR /root

RUN apt-get update -y &&\
    wget https://go.dev/dl/go1.21.6.linux-amd64.tar.gz &&\
    tar -xvf go1.21.6.linux-amd64.tar.gz &&\
    rm -rf go1.21.6.linux-amd64.tar.gz &&\
    mv go /usr/local &&\
    export GOROOT=/usr/local/go &&\
    export GOPATH=$HOME/go &&\
    export PATH=$GOPATH/bin:$GOROOT/bin:$PATH &&\
    go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest

RUN CGO_ENABLED=1 xcaddy build --with github.com/mliezun/caddy-snake

# Use caddy binary located in: /root/caddy

Example Caddyfile

{
	http_port 9080
	https_port 9443
	log {
		level error
	}
}
localhost:9080 {
    route {
        python "simple_app:main"
    }
}

The python rule is an HTTP handler that expects a wsgi app as an argument.

Examples

  • simple_app. WSGI App that returns the standard hello world message and a UUID.
  • example_flask. Flask application that also returns hello workd message and a UUID.

NOTE

At the moment there's no support for virtual environments. To use one is necessary to set the PYTHONPATH env variable when starting caddy. As follows:

PYTHONPATH="venv/lib/python3.12/site-packages/" caddy run --config Caddyfile

Make sure to use the right python version depending on your case ^.

Dev resources

LICENSE

MIT License.

caddy-snake's People

Contributors

mliezun avatar

Watchers

 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.