Skip to main content

The Python backbone for jdm-electron-flask desktop apps

Project description

jdm-electron-flask (Python)

The Python backbone for jdm-electron-flask desktop apps.

This package ships inside every project scaffolded by the jdm-cli electron-flask plugin. It provides the app factory, dynamic API registration, SocketIO setup, and environment-aware logging — so you build features, not boilerplate.


Installation

You don't install this manually. It's included in the scaffolded requirements.txt:

jdm-electron-flask==1.0.0

If you need it standalone:

pip install jdm-electron-flask

What it provides

create_app

The Flask app factory. Handles config loading, SocketIO init, blueprint auto-discovery, and the React SPA catch-all route.

# run.py
from jdm_electron_flask import create_app, get_socketio

app = create_app()
socketio = get_socketio()

if __name__ == "__main__":
    socketio.run(app, host="0.0.0.0", port=5000, debug=True)

JDMBlueprint

Extended Blueprint with built-in response helpers.

from jdm_electron_flask import JDMBlueprint

health_bp = JDMBlueprint("health", __name__)

@health_bp.route("/health")
def health():
    return health_bp.success({"status": "ok"})

JDMEvents

Base class for organizing socket event handlers.

from jdm_electron_flask import JDMEvents

class ConnectEvents(JDMEvents):
    def register(self):
        @self.socketio.on("connect")
        def on_connect():
            self.on_connect()

        @self.socketio.on("ping_server")
        def on_ping(data):
            self.emit("pong_client", {"echo": data})

ConnectEvents().register()

Printer

Environment-aware logger. Prints in development, writes to logs/<date>.log in production/deployed.

from jdm_electron_flask import Printer

Printer.success("Blueprint registered")
Printer.warn("Something is off")
Printer.error("Something broke")
Printer.info("Just FYI")

Response helpers

from jdm_electron_flask import success, error, paginate

return success({"user": "JDM"})
return error("Not found", status=404)
return paginate(items, total=100, page=1, per_page=10)

Validators

from jdm_electron_flask import validate_fields

valid, msg, data = validate_fields(["name", "email"])
if not valid:
    return error(msg)

Dynamic API registration

Routes are controlled by config/api.json:

{
    "health": {
        "link": "/api",
        "masterEnabled": true
    },
    "users": {
        "link": "/api/users",
        "masterEnabled": true,
        "disabledOnProduction": false,
        "disabledOnDeployed": false
    }
}

Adding a new route:

  1. Add entry to config/api.json
  2. Create app/api/users.py with a users_bp blueprint

That's it. No touching __init__.py ever again.


Environment modes

FLASK_ENV Behavior
development Debug on, console logging, all routes enabled
production Debug off, file logging, respects disabledOnProduction
deployed Debug off, file logging, respects disabledOnDeployed

Companion

This package is the Python half of the jdm-electron-flask ecosystem:

Package Role
jdm-electron-flask (npm) CLI plugin — scaffold, build, compile
jdm-electron-flask (PyPI) Backend library — app factory, blueprints, sockets

License

MIT © JDM-Github

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

jdm_electron_flask-1.0.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

jdm_electron_flask-1.0.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file jdm_electron_flask-1.0.1.tar.gz.

File metadata

  • Download URL: jdm_electron_flask-1.0.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for jdm_electron_flask-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3e6f438bda2fbf21e42c62e1897ee3fd5af182b761e9dd19d4aa6ae9d30c551a
MD5 5b2b303b9b81b37194aa005a16ebad2b
BLAKE2b-256 9d4b43f13342d8aa1c944e87258913d93620a17cca222bb81c1667242eb5461e

See more details on using hashes here.

File details

Details for the file jdm_electron_flask-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for jdm_electron_flask-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6a63cd0b9f3a1eadd33eda2a0daebcf460c80eca42e8b3255fac6f95c505896d
MD5 0bb4257d9cc4e56d3913c82c66cf7711
BLAKE2b-256 6e24c5d4923c0d669558c3b73fec2a4307d200857a1a4f43765aa6af7fb32570

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