Skip to main content

Python bindings for Endless Sky C++ code

Project description

Endless Sky bindings for Python

Play with the Endless Sky C++ classes from Python or interact with the game as it runs.

pip install endless-sky-bindings

This library does not include the Endless Sky data, so to load that data you'll need to find the installed copy on your system or clone the Endless Sky repo to get it. The code samples below assume a checkout of endless-sky at ~/endless-sky.

Library

Once you get a handle on the endless_sky.bindings module (bound to 'es' variable here), C++ classes are exposed to Python pretty directly; for documentation, see the header files in Endless Sky.

>>> from endless_sky.loader import load_data
>>> es = load_data(resources="/Users/tomb/endless-sky")
>>> ships = es.GameData.Ships() # these objects correspond to 
>>> ships.<tab><tab>
ships.Get(   ships.Has(   ships.size(
>>> shuttle = ships.Get("Shuttle")
<endless_sky.bindings.Ship object at 0x1087391b0>
>>> ship = es.Ship(shuttle)  # make a copy to avoid modifying the template
>>> ship.<tab><tab>
ship.Acceleration(          ship.Hull(                  ship.Mass(
ship.AddCrew(               ship.HyperdriveFuel(        ship.MaxReverseVelocity(
ship.Attributes(            ship.IdleHeat(              ship.MaxVelocity(
ship.BaseAttributes(        ship.IsBoarding(            ship.MaximumHeat(
... and many more, see header files for documentation
>>> ship.Attributes().Attributes()
<endless_sky.bindings.Dictionary object at 0x1087392f0>
>>> dict(ship.Attributes().Attributes())
{'bunks': 6.0, 'cargo space': 20.0, 'drag': 1.7000000000000002, ...}
>>> ship.SetName("Summer Breeze")
>>> x.Name()
'Summer Breeze'

Warning: endless_sky.bindings contains non-resetable singletons like GameData, so once you load some data (directly with GameData.BeginLoad(), with a load_data, or indirectly with a parser function) you can't unload that data without exiting Python.

Command line use

Loading data files:

% echo -e 'ship Rocket\n\tattributes\n\t\tdrag 10' > myData.txt
$ python -m endless_sky load --empty-resources myData.txt  # only prints ships atm
'Rocket': {'drag': 10.0, 'gun ports': 0.0, 'turret mounts': 0.0},
$ python -m endless_sky load -- --resources ~/endless-sky
{'Aerie': {'bunks': 28.0,
           'capture attack': 1.8000000000000003,
           'capture defense': 2.4000000000000004,
           'cargo space': 50.0,
...
$ # In order to parse a file with vanilla outfits defined, use --resources
$ python -m endless_sky load --resources ~/endless-sky myData.txt
{'Aerie': {'bunks': 28.0,
...
<'Rocket' is somewhere in here>
...

Runing the game and a Python interpreter at the same time:

$ python -m endless_sky run --resources ~/endless-sky --default-config

Building from source

git clone --recursive git@github.com:thomasballinger/endless-sky-bindings-python.git
cd endless-sky-bindings-python

Mac

brew install libmad libpng jpeg-turbo SDL2 openal-soft

Linux

sudo apt-get install libsdl2-dev libpng-dev libjpeg-turbo8-dev libopenal-dev libmad0-dev libglew-dev libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev uuid-dev

Windows

Invoke-WebRequest https://endless-sky.github.io/win64-dev.zip -OutFile win64-dev.zip
Expand-Archive win64-dev.zip -DestinationPath . -Force
Remove-Item win64-dev.zip

cd endless_sky/endless-sky
patch -p1 < ../../patch.diff
cd ../..
pip install 

Dev notes

Updating the Endless Sky patch

These bindings use a patched version of Endless Sky to patch out threads and make a few other changes.

To update the patch:

  • make changes in the submodule at endless_sky/endless-sky
  • with that directory as the working directory, run git diff > ../../patch.diff

This is likely to be necessary after updating the version of Endless Sky used.

This patch is intended to be the minimum to make Python bindings work; if this repo is combined with Emscripten-compiled JavaScript bindings at a later date it will need to be expanded.

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

endless-sky-bindings-0.0.13.tar.gz (686.1 kB view details)

Uploaded Source

Built Distributions

endless_sky_bindings-0.0.13-cp39-cp39-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

endless_sky_bindings-0.0.13-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

endless_sky_bindings-0.0.13-cp39-cp39-macosx_10_15_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

endless_sky_bindings-0.0.13-cp38-cp38-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.8 Windows x86-64

endless_sky_bindings-0.0.13-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

endless_sky_bindings-0.0.13-cp38-cp38-macosx_10_15_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

Details for the file endless-sky-bindings-0.0.13.tar.gz.

File metadata

  • Download URL: endless-sky-bindings-0.0.13.tar.gz
  • Upload date:
  • Size: 686.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for endless-sky-bindings-0.0.13.tar.gz
Algorithm Hash digest
SHA256 dc227d07ab5ae287be21a847dd0ae71d2c916cda73119d14855863d6f9d326d7
MD5 fc4709749d73e9780e2a5b242549a0ed
BLAKE2b-256 7d7eaf21c3a5d270e0757484e7451e4eacffbb91cd0e0c469faee7f84661b8c2

See more details on using hashes here.

File details

Details for the file endless_sky_bindings-0.0.13-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: endless_sky_bindings-0.0.13-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 4.1 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for endless_sky_bindings-0.0.13-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a0aeb39ee7d9c819e9b6923319b704ec4d013870a4b9473e3b06b058dffb1e9a
MD5 b9b8bd8957cb2474b0cc05c571a98ff7
BLAKE2b-256 7d218a94432a53b31aa733c67a28b57259c373b8f8dc253aaeb08a66ef78469b

See more details on using hashes here.

File details

Details for the file endless_sky_bindings-0.0.13-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for endless_sky_bindings-0.0.13-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2f6e783f9efaf330d0ac2680d87465262995bddee6410cb9ee8d5fe435fb1212
MD5 f5b209c099499e2c5081ab313ccd894a
BLAKE2b-256 fa2f8d42960c07b18de59416d2f12c7fe72a1c193c6ec47c4aa0dde92f35d9d1

See more details on using hashes here.

File details

Details for the file endless_sky_bindings-0.0.13-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: endless_sky_bindings-0.0.13-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for endless_sky_bindings-0.0.13-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ddf746861d23dfad02af821e6dff13d76f4b755393545ee21dc205a9b250be7a
MD5 8fc6c5ecf61e6257f97efd89be9f12a2
BLAKE2b-256 1b8014a960759a8783be280e722aced953f566249c84bb7549a24f4ab591f67c

See more details on using hashes here.

File details

Details for the file endless_sky_bindings-0.0.13-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: endless_sky_bindings-0.0.13-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 4.1 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for endless_sky_bindings-0.0.13-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 1e451095f20aa2ff3bc571922af77106715c0e319df9e346057589373e2c3b33
MD5 75067a64cd43755c0439d23bf90b7c09
BLAKE2b-256 bb0e61373c8fe12633b72b03165de3a37ec4bb94b28432c9262f176e02a87a42

See more details on using hashes here.

File details

Details for the file endless_sky_bindings-0.0.13-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for endless_sky_bindings-0.0.13-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 365fedba10be15251e18cc2cad1e7997fc5803a6a371df730ea048890b4d1e47
MD5 f7e9940f39999adaa31f0bfaeb7135d9
BLAKE2b-256 cf5e3053d4ad07f2753da227b7982d38751f9cdeb879e3c2d75abecbe49c0563

See more details on using hashes here.

File details

Details for the file endless_sky_bindings-0.0.13-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: endless_sky_bindings-0.0.13-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for endless_sky_bindings-0.0.13-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 07a0fd623c8d0f2ed0a75674f1fb8ec3834d8d8f64793d9ec78f284e8493ea11
MD5 64489c1681f233961608ab40c4aa03a9
BLAKE2b-256 cd86a9838cf5207cb2c0f9b1eb7c7a3eb78e1a53d8f3dcdef947a8520bf163ac

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page