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.Find(  ships.Has(   ships.size(
>>> shuttle = ships.Find("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 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.12.tar.gz (685.7 kB view details)

Uploaded Source

Built Distributions

endless_sky_bindings-0.0.12-cp39-cp39-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.9 Windows x86-64

endless_sky_bindings-0.0.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

endless_sky_bindings-0.0.12-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.12-cp38-cp38-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.8 Windows x86-64

endless_sky_bindings-0.0.12-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

endless_sky_bindings-0.0.12-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.12.tar.gz.

File metadata

  • Download URL: endless-sky-bindings-0.0.12.tar.gz
  • Upload date:
  • Size: 685.7 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.12.tar.gz
Algorithm Hash digest
SHA256 9ba8f2ba948c12dba6fa325fa8f5b2047fc13062374862cd07ead4a20809a9c0
MD5 a24cb4d7796b849fe2c91547006d5af5
BLAKE2b-256 a5f2ec2fe8d386ae288af243f2e25c3198ad0505bb4f03f86ce1d8f95e1c4e4b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: endless_sky_bindings-0.0.12-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 4.2 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.12-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c98314d69c0b8184788bd84f5d94db7f63225c159792727544b317b15e29b558
MD5 69b9cff4176f3ed3d994c67593ddb432
BLAKE2b-256 d48463d03eb59c318e5fc1ab560773ae708ea1610b535bd704f01214839631e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for endless_sky_bindings-0.0.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 733c39e1ed8ed45073a4ccf827461409375187ac37fa9d676c0c31074019b18c
MD5 4b580236c255cd803e4a3bee00da51a9
BLAKE2b-256 54f540da5757a4ef21a0b17776c11517b5b0ab2bb5e9f8e030718da59e909b63

See more details on using hashes here.

File details

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

File metadata

  • Download URL: endless_sky_bindings-0.0.12-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.12-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 86dd240866680a6e8fadc9910d3db06fadeb38bfbd0c5aba58c7393c2a2715fe
MD5 b11201953408af2e7804d8f118c77731
BLAKE2b-256 67575239956a071570336112bc753d653a8a4fcbec224dd4f47eeda967631179

See more details on using hashes here.

File details

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

File metadata

  • Download URL: endless_sky_bindings-0.0.12-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.12-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 44f30db6e684dc60ddb773819ba678335d4ed2827227e79be808aa6ea4e27fad
MD5 e67f2659d220dfe8e54424865162cade
BLAKE2b-256 6781777f3654a0cb4501ea7906aa7ae279d456089076064c69cacca59961c7e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for endless_sky_bindings-0.0.12-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9850a418e1936ecc095a20163f12b230a10baf3b1aa0117f913652af16f9f7d0
MD5 19ff3aa24124a12f4c2085587812a17f
BLAKE2b-256 978c6ce1a54a1347303e4b4370a233679fa2c9902d7466d53d7519ac6fa4fc0a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: endless_sky_bindings-0.0.12-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.12-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 a17a0fabfdf7b9c1bf5bd0010970b8e9d91b57c378a39181e21b79fac0532c8e
MD5 63ff32c457b03c8a99c5ad09bbfba09c
BLAKE2b-256 1921829ccfc79c7e7e33e4e373a933927892acf9cb44cc2af9b9f45322052bde

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