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.

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.

⚙️ | 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.0.2.tar.gz (93.6 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.0.2-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pythontosw-2.0.2.tar.gz
Algorithm Hash digest
SHA256 b142532a58d5f48e383c9e37d1243e2c5cf6cffc57e2b82e798db2cfa1540d6f
MD5 e1ed831f4ec292738c02b304971d424c
BLAKE2b-256 66933aae620f229610fbb362940edd1e5aa10327a6c699690a6e3c8b6c14b3f5

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pythontosw-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ecafb7d5f1718bc372b775cd500f6aed7bc84ba65684f1894babc99cd927556b
MD5 43fd015a7d059fe57bfacb01b51f87c2
BLAKE2b-256 9160e1b1562330e694cf8111f932bb84fafe024354e1192df68ddc91da0782a7

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