Skip to main content

Python support for Puff

Project description

Python for ☁ Puff ☁!

puff-py provides support to run Python on the puff runtime.

See the official puff repository for more details.

There is also an integrated example with Django found in this repo's /examples folder which gives specific guidance on how to use Django

To use the example

cd ./examples/hello_world_puff
cargo build
cd hello_world_py_app
poetry install
poetry run cargo run runserver

You may have to adjust your PUFF_POSTGRES_URL and PUFF_REDIS_URL to your local Postgres and redis instances to get it to run.

Using Django with Puff

Set up your project:

cargo new my_puff_proj --bin
cd my_puff_proj
cargo add puff-rs
poetry new my_puff_proj_py
cd my_puff_proj_py
poetry add puff-py
poetry add django
poetry run django-admin startproject hello_world_django_app .

Add Django to your Puff Program

use puff_rs::program::commands::{PytestCommand, WSGIServerCommand, DjangoManagementCommand};
use puff_rs::graphql::handlers::{handle_graphql, handle_subscriptions, playground};
use puff_rs::prelude::*;


fn main() -> ExitCode {
    let rc = RuntimeConfig::default()
        .add_env("DJANGO_SETTINGS_MODULE", "hello_world_django_app.settings")
        .set_postgres(true)
        .set_redis(true)
        .set_pubsub(true)
        .set_gql_schema_class("hello_world_py_app.Schema");

    let router = Router::new()
            .get("/", playground("/graphql", "/subscriptions"))
            .post("/graphql", handle_graphql())
            .get("/subscriptions", handle_subscriptions());

    Program::new("puff_django_app_example")
        .about("This is my first graphql app")
        .runtime_config(rc)
        .command(DjangoManagementCommand::new())
        .command(WSGIServerCommand::new_with_router("hello_world_django_app.wsgi.application", router))
        .command(PytestCommand::new("."))
        .run()
}

Change your settings to use Puff Database and Redis Cache

DATABASES = {
    'default': {
        'ENGINE': 'puff.contrib.django.postgres',
        'NAME': 'global',
    }
}

CACHES = {
    'default': {
        'BACKEND': 'puff.contrib.django.redis.PuffRedisCache',
        'LOCATION': 'redis://global',
    }
}

Change wsgi.py to serve static files;

...

from django.core.wsgi import get_wsgi_application
from django.contrib.staticfiles.handlers import StaticFilesHandler

application = StaticFilesHandler(get_wsgi_application())

Use Poetry and Cargo run instead of ./manage.py

poetry run cargo run runserver
poetry run cargo run django migrate

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

puff_py-0.1.7.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

puff_py-0.1.7-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file puff_py-0.1.7.tar.gz.

File metadata

  • Download URL: puff_py-0.1.7.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.7 Darwin/21.5.0

File hashes

Hashes for puff_py-0.1.7.tar.gz
Algorithm Hash digest
SHA256 befd2ee47353dee53336f0fd3b3693d8953d07449f494955c1fd552408ca2be9
MD5 a75b140464c798c899d659620fbdab71
BLAKE2b-256 83c375cef2f930cf8b5bf353b43ec9e6c7d75c485abb9534bbbff38e8dffa017

See more details on using hashes here.

File details

Details for the file puff_py-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: puff_py-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.7 Darwin/21.5.0

File hashes

Hashes for puff_py-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 46aacfecbfd771dbf1ba1e234d70f901c8433afc10475bfd483f777374159607
MD5 c9b3acd4320bb2ef479daa36c5f0d7f7
BLAKE2b-256 b72e4fff4c9bc32b5e07fd3ff72f5290a3e2d77b57f80c82a31d82d0db0ef866

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page