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 install puff-py
poetry install 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file puff_py-0.1.3.tar.gz.
File metadata
- Download URL: puff_py-0.1.3.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.10.7 Darwin/21.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb4fe82b78a22882b4d464195bffaf959188e0ed56c82336af03e7971ae32765
|
|
| MD5 |
64acc39f1fd1fc67730521af37a72994
|
|
| BLAKE2b-256 |
dbfbf0505ef04269380e868c892e2c4db48dcb787f859dd2287460c01951efb8
|
File details
Details for the file puff_py-0.1.3-py3-none-any.whl.
File metadata
- Download URL: puff_py-0.1.3-py3-none-any.whl
- Upload date:
- Size: 25.6 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b43211be7ee9a25a0b91be8b5b250b8f9bbec9e452a28795509946636b1d77df
|
|
| MD5 |
28aa540833969644b70d6cee30d51fb4
|
|
| BLAKE2b-256 |
4bebb56bc48308fd57ee84254b9462d879a4a06f44f2900c7cc8c54502001453
|