Skip to main content

A lightweight, beginner-friendly yet powerful Python web framework

Project description

ProAPI

A lightweight, beginner-friendly yet powerful Python web framework.

Features

  • Decorator-based routing (@app.get(), @app.post(), etc.)
  • Simple template rendering with Jinja2
  • Easy server startup with app.run()
  • Optional async support
  • Optional Cython-based compilation for speed boost
  • Minimal dependencies
  • Built-in JSON support
  • Middleware/plugin system
  • Automatic API documentation
  • Structured logging with Loguru
  • Smart auto-reloader for development
  • Port forwarding to expose apps to the internet
  • CLI commands

Installation

pip install proapi

This will install ProAPI with all core dependencies including:

  • loguru (for logging)
  • uvicorn (for ASGI server and auto-reloading)
  • cython (for performance optimization)
  • jinja2 (for templating)
  • watchdog (for file monitoring)

For development tools:

pip install proapi[dev]

For production extras:

pip install proapi[prod]

For Cloudflare Tunnel support:

pip install proapi[cloudflare]

Quick Start

from proapi import ProAPI

app = ProAPI(debug=True)

@app.get("/")
def index(request):
    return {"message": "Hello, World!"}

@app.get("/hello/{name}")
def hello(name, request):
    return {"message": f"Hello, {name}!"}

if __name__ == "__main__":
    app.run()

API Documentation

ProAPI can automatically generate API documentation for your application using Swagger UI:

app = ProAPI(
    debug=True,
    enable_docs=True,
    docs_url="/docs",
    docs_title="My API Documentation"
)

This will make interactive Swagger UI documentation available at /docs and OpenAPI specification at /docs/json.

Additionally, ProAPI automatically provides a default documentation endpoint at /.docs for all applications, regardless of whether you explicitly enable documentation. This makes it easy to quickly access API documentation without any additional configuration.

Port Forwarding

ProAPI can automatically expose your local server to the internet:

# Enable port forwarding in the app
app = ProAPI(enable_forwarding=True)

# Or enable it when running
app.run(forward=True)

# Use Cloudflare Tunnel
app.run(forward=True, forward_type="cloudflare")

# Use localtunnel
app.run(forward=True, forward_type="localtunnel")

You can also enable it from the CLI:

# Use ngrok (default)
proapi run app.py --forward

# Use Cloudflare Tunnel
proapi run app.py --forward --forward-type cloudflare

# Use Cloudflare with an authenticated tunnel
proapi run app.py --forward --forward-type cloudflare --cf-token YOUR_TOKEN

# Use localtunnel
proapi run app.py --forward --forward-type localtunnel

Template Rendering

from proapi import ProAPI, render

app = ProAPI()

@app.get("/")
def index():
    return render("index.html", title="Home", message="Welcome!")

Async Support

from proapi import ProAPI

app = ProAPI()

@app.get("/async-example")
async def async_example():
    # Perform async operations
    await some_async_function()
    return {"result": "Async operation completed"}

Middleware

from proapi import ProAPI

app = ProAPI()

@app.use
def logging_middleware(request):
    print(f"Request: {request.method} {request.path}")
    return request

@app.get("/")
def index():
    return {"message": "Hello, World!"}

Logging with Loguru

ProAPI integrates with Loguru for structured logging:

from proapi import ProAPI, app_logger

# Configure logging in the app
app = ProAPI(
    debug=True,
    log_level="DEBUG",
    log_format="<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan> - <level>{message}</level>",
    log_file="logs/app.log"
)

@app.get("/")
def index(request):
    app_logger.info(f"User accessed the home page")
    return {"message": "Hello, World!"}

# Use structured logging with context
@app.get("/users/{user_id}")
def get_user(user_id, request):
    # Add context to logs
    logger = app_logger.bind(user_id=user_id)
    logger.info("User details requested")

    # Log different levels
    if not user_id.isdigit():
        logger.warning("Invalid user ID format")
        return {"error": "Invalid user ID"}

    return {"id": user_id, "name": "Example User"}

Auto-Reloader

ProAPI includes auto-reloading for development that automatically restarts the server when code changes are detected. It uses uvicorn's reloader for maximum reliability:

from proapi import ProAPI

# Enable auto-reloader in the app
app = ProAPI(
    debug=True,
    use_reloader=True  # Requires uvicorn: pip install uvicorn
)

@app.get("/")
def index():
    return {"message": "Edit this file and save to see auto-reload in action!"}

if __name__ == "__main__":
    app.run()

You can also enable it when running:

app.run(use_reloader=True)

Or from the CLI:

proapi run app.py --reload

Note: Auto-reloading is powered by uvicorn, which is now included as a core dependency.

CLI Commands

Create a new project:

proapi create myproject

Run an application:

proapi run app.py --debug --reload

Performance Optimization

ProAPI can be compiled with Cython for better performance:

proapi run app.py --compile

License

MIT

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

proapi-0.1.0.tar.gz (38.1 kB view details)

Uploaded Source

Built Distribution

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

proapi-0.1.0-py3-none-any.whl (40.9 kB view details)

Uploaded Python 3

File details

Details for the file proapi-0.1.0.tar.gz.

File metadata

  • Download URL: proapi-0.1.0.tar.gz
  • Upload date:
  • Size: 38.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for proapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3b4d350c0c978165a7ce665cbb6e171431828d1ed1550d28bc83248d9fb10f81
MD5 714914cd6ad5c979cdd3569814b80cc3
BLAKE2b-256 f4ace70e7fb1959f56e3ff981139c1a76f3847a610d6cd1ea6910c42922b6fe8

See more details on using hashes here.

File details

Details for the file proapi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: proapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 40.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for proapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7822b6241a92782eb599c5d808cc1224492ba1191a0cc1d99e01bb04a70eac5
MD5 f334f8338690ef5c3c2d864e9666c446
BLAKE2b-256 40cd9d442bc505b94270e15b4bc8b90d66f94bec0655134d8afbc4863a9e0d8f

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