Skip to main content

A package that allows you to create addons in Stormworks with Python, handled through HTTP.

Project description

Banner

📚 | Overview

PythonToSW is a Python package that allows you to create addons in Stormworks: Build and Rescue with Python through HTTP using FastAPI under the hood.

Documentation: https://pythontosw.cuhhub.com/

Working Example

from PythonToSW import (
    Addon,
    CallEnum,
)

addon = Addon(
    "Testing",
    path = ".",
    port = 2000
)

def on_start():
    """
    Called when the addon starts (connects with in-game addon).
    """
    
    # If you was to code a Lua addon with the same behaviour, it'd look like: server.announce("Server", "Hello world!")
    addon.call(CallEnum.ANNOUNCE, "Server", "Hello world!")
    
def on_stop():
    """
    Called when the addon stops (disconnects with in-game addon).
    """
    
    print("Whups, we lost connection!")
    
def on_tick():
    """
    Called every addon tick.
    """
    
    pass
    
# Call `on_tick` every addon tick
# Note that this doesn't connect to the in-game `onTick` callback as HTTP would not be able to keep up
# Instead, this is a simulated version that is called at a manageable rate (32 TPS, theoretical max)
addon.on_tick += on_tick

# Start the addon
# `on_start` is called when the in-game addon connects
# `on_stop` is called when the in-game addon disconnects (game exited, etc.)
addon.start(on_start, on_stop)

More examples can be found in the examples directory.

📚 | Documentation

Click here for the documentation.

⚙️ | Installing this package

  • Use pip install PythonToSW --upgrade
  • Import the package with import PythonToSW as PTS in your code

✅ | Advantages

  • Since the addon is running outside of the game, you get much more control with your addon and aren't limited by the limitations of Stormworks Lua.
    • You can send HTTP requests to places other than localhost, and using methods other than GET.
    • You can write to/read from files.
    • ... and so on.
  • Classes (since we're using Python here)
  • The source code of your addon can't be accessed via malicious actors.
    • Yup. If someone with malicious intent is in a server with an addon, they can get the addon's raw code (although difficult to do).
    • Because PythonToSW uses HTTP and doesn't compile code to Lua, the Python source code is completely hidden and the only code malicious actors can get is the Lua code that connects to the PythonToSW server (which is already open-source).

❌ | Disadvantages

  • Noticeable delays. This project works through HTTP instead of converting Python code to Lua code, and HTTP is unfortunately slow (limited to one request every two ticks, aka 32 requests/sec).
  • For your addon to function, the host of the server must run the Python script behind your addon. Closing the Python script will essentially stop the addon.
  • Uploading your addon to the workshop is pointless as the Python code is what makes your addon work. Distributing your addon therefore becomes harder and less convenient for users to download and use.

✨ | Credit

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

pythontosw-2.1.0.tar.gz (98.2 kB view details)

Uploaded Source

Built Distribution

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

pythontosw-2.1.0-py3-none-any.whl (104.0 kB view details)

Uploaded Python 3

File details

Details for the file pythontosw-2.1.0.tar.gz.

File metadata

  • Download URL: pythontosw-2.1.0.tar.gz
  • Upload date:
  • Size: 98.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pythontosw-2.1.0.tar.gz
Algorithm Hash digest
SHA256 2c4705255a38fb216629d29f48756cb8147441e3b30d35b750dfe446f9a267d9
MD5 e440de2cb2e4c05c812b8327d63cafe9
BLAKE2b-256 8a1ddd2c4b4b7904e3524d720a869cc92e0a830138e14e92d9d70f74dd6f6ce2

See more details on using hashes here.

File details

Details for the file pythontosw-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: pythontosw-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 104.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pythontosw-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a11d7d155e54068612ff3c162c217324acc06d4b6d7256080353ebe0450e611f
MD5 9cfaa353a4eb4be5c22de61af4cff64f
BLAKE2b-256 1954e02e8e3ba6653852328776b430d8ad50453ee4466a776d75fc1a5c6df173

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