npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@platformatic/python

v2.0.0

Published

Integration of Python with Wattpm

Readme

@platformatic/python

A Python stackable for Platformatic that enables running Python ASGI applications within the Platformatic ecosystem. This package integrates Python execution with Fastify servers, allowing you to serve Python applications alongside Node.js applications.

Features

  • 🚀 Run Python ASGI applications within Platformatic services
  • 🔄 Automatic request/response handling between Node.js and Python
  • 📁 Static file serving for non-Python assets
  • ⚡ Hot reloading during development
  • 🛠️ Code generation for new Python projects
  • 🔧 Environment-based configuration

Requirements

Installation

npm install @platformatic/python

Quick Start

Create a New Python Project

npx --package=@platformatic/python create-platformatic-python --dir my-python-app --port 3042
cd my-python-app
npm install
npm start

CLI Options

  • --dir - Target directory (default: plt-python)
  • --port - Server port (default: 3042)
  • --hostname - Server hostname (default: 0.0.0.0)
  • --main - Main Python file (default: main.py)

Configuration

The stackable uses a platformatic.json configuration file:

{
  "$schema": "https://schemas.platformatic.dev/@platformatic/python/0.7.0.json",
  "module": "@platformatic/python",
  "python": {
    "docroot": "public",
    "appTarget": "main:app"
  },
  "server": {
    "hostname": "{PLT_SERVER_HOSTNAME}",
    "port": "{PORT}",
    "logger": { "level": "{PLT_SERVER_LOGGER_LEVEL}" }
  },
  "watch": true
}

Configuration Options

python

  • docroot (string, required) - Path to the root directory containing Python files
  • appTarget (string, optional) - The Python module and function to load in the format module:function (default: main:app)

server

Standard Platformatic server configuration options are supported.

Project Structure

A generated Python project includes:

my-python-app/
├── public/
│   └── main.py            # Main Python ASGI application
├── .env                   # Environment variables
├── .env.sample           # Environment template
├── .gitignore
├── package.json
└── platformatic.json     # Platformatic configuration

Development

Available Scripts

  • npm start - Start the development server
  • npm test - Run tests
  • npm run build - Build schema and types

Environment Variables

  • PLT_SERVER_HOSTNAME - Server hostname (default: 0.0.0.0)
  • PORT - Server port (default: 3042)
  • PLT_SERVER_LOGGER_LEVEL - Log level (default: info)

How It Works

  1. Request Routing: All HTTP requests are captured by wildcard routes
  2. Python Execution: Requests are forwarded to Python ASGI applications via @platformatic/python-node
  3. Static Files: Non-Python files in the docroot are served statically
  4. Response Handling: Python ASGI responses are processed and returned through Fastify

API

Stackable Export

import { stackable } from '@platformatic/python'
// or
import python from '@platformatic/python'

Generator

import { Generator } from '@platformatic/python'

const generator = new Generator()
generator.setConfig({
  targetDirectory: './my-app',
  port: 3042,
  hostname: '0.0.0.0'
})
await generator.run()

Examples

Basic Python ASGI Application

# public/main.py
import json
from datetime import datetime

async def app(scope, receive, send):
    """
    Basic ASGI application
    """
    if scope["type"] == "http":
        await send({
            'type': 'http.response.start',
            'status': 200,
            'headers': [
                [b'content-type', b'application/json'],
            ],
        })

        response_data = {
            "message": "Hello from Python!",
            "timestamp": datetime.now().isoformat()
        }

        await send({
            'type': 'http.response.body',
            'body': json.dumps(response_data).encode('utf-8'),
        })

Handling POST Requests

# public/api.py
import json

async def app(scope, receive, send):
    """
    ASGI application that handles POST requests
    """
    if scope["type"] == "http":
        method = scope["method"]

        if method == "POST":
            # Read the request body
            body = b''
            while True:
                message = await receive()
                if message['type'] == 'http.request':
                    body += message.get('body', b'')
                    if not message.get('more_body', False):
                        break

            # Parse JSON body
            try:
                input_data = json.loads(body.decode('utf-8'))
            except:
                input_data = {}

            await send({
                'type': 'http.response.start',
                'status': 200,
                'headers': [
                    [b'content-type', b'application/json'],
                ],
            })

            response_data = {
                "received": input_data,
                "method": method
            }

            await send({
                'type': 'http.response.body',
                'body': json.dumps(response_data).encode('utf-8'),
            })

Contributing

This project is part of the Platformatic ecosystem. Please refer to the main repository for contribution guidelines.

License

Apache-2.0

Support