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
Release history Release notifications | RSS feed
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.6.tar.gz
(24.8 kB
view hashes)
Built Distribution
puff_py-0.1.6-py3-none-any.whl
(30.2 kB
view hashes)