This release is a pre-release and may not be stable for production use.
shapeio
This Python module provides functions to decode MSTS/ORTS shape files into Python objects and to encode them back into the shape file format. The API is very similar to that of the json module.
⚠️ Deprecation Notice ⚠️
This library is deprecated and will no longer be actively maintained.
Please migrate to simisa for continued development, updates, and support.
The new simisa library also supports reading and writing shapes in compressed/binary format without relying upon external tools like ffeditc_unicode.exe.
This package will remain available for existing users, but new projects should use the replacement library instead.
Installation
The Python module itself can be installed in the following ways:
Install from PyPI
pip install --upgrade shapeio
Install from wheel
If you have downloaded a .whl file from the Releases page, install it with:
pip install path/to/shapeio‑<version>‑py3‑none‑any.whl
Replace <version> with the actual version number in the filename.
Install from source
git clone https://github.com/pgroenbaek/shapeio.git
pip install --upgrade ./shapeio
Usage
Load a shape from a file
To load a shape from disk, use the shapeio.load function. Note that the shape file must be decompressed beforehand. Otherwise, you will get a ShapeCompressedError.
See the pyffeditc or pytkutils modules for how to decompress a shape, depending on if you want to use the ffeditc_unicode.exe utility or the TK.MSTS.Tokens.dll library by Okrasa Ghia.
import shapeio
my_shape = shapeio.load("./path/to/example.s")
print(my_shape)
Save a shape to a file
To save a shape to disk, you can use the shapeio.dump function. This will serialize the shape object, including any changes made to it, into the structured text format and save it to the specified path.
import shapeio
shapeio.dump(my_shape, "./path/to/output.s")
Serialize a shape to a string
If you want to serialize the object into a string without saving it to a file on disk, you can use shapeio.dumps.
import shapeio
shape_string = shapeio.dumps(my_shape)
print(shape_string)
Parse a shape from a string
Similarly, you can use shapeio.loads to parse a shape from a string instead of reading it from a file on disk.
import shapeio
shape_text = """
SIMISA@@@@@@@@@@JINX0s1t______
shape (
shape_header ( 00000000 00000000 )
volumes ( 12
vol_sphere (
vector ( -1.23867 3.5875 40 ) 42.452
)
vol_sphere (
vector ( -1.23867 0.495151 40 ) 40.1839
)
...
"""
shape = shapeio.loads(shape_text)
Accessing shape data
The functions that load shapes return a Shape object, allowing you to access all the data defined in the shape file.
To explore the full data structure, see shape.py. You can also print the objects to view their attributes.
import shapeio
my_shape = shapeio.load("./path/to/example.s")
# Print the point at index 17.
print(my_shape.points[17])
# Iterate over uv_points, print uv_point at index 10.
for idx, uv_point in enumerate(my_shape.uv_points):
if idx == 10:
print(uv_point)
Modifying shape data
You can modify values, add or remove items from lists, and reorder items in the lists. The serialized shape data will reflect any changes you make.
import shapeio
from shapeio import shape
my_shape = shapeio.load("./path/to/example.s")
# Modify an existing point.
my_shape.points[1].x = 17
# Add a new uv_point.
new_uv_point = shape.UVPoint(0.2, 0.5)
my_shape.uv_points.append(new_uv_point)
shapeio.dump(my_shape, "./path/to/output.s")
When using this module by itself, there are no built-in safeguards beyond the data structure to ensure that modifications will result in a shape usable in MSTS or Open Rails.
See shapeedit for a wrapper that allows performing complex operations on the data structure safely.
However, this module will ensure that list counts in the serialized data are correct. It also enforces strict type checking during serialization, which prevents adding items to lists and setting values of attributes that are not of the expected type.
Running Tests
You can run tests manually or use tox to test across multiple Python versions.
Run Tests Manually
First, install the required dependencies:
pip install pytest pytest-dependency
Then, run tests with:
pytest
Run Tests with tox
First, install the required dependencies:
pip install tox pytest pytest-dependency
Then, run tests with:
tox
This will execute tests for all Python versions specified in tox.ini.
Roadmap
Possible future features to be added:
- Reading compressed shapes
- Writing compressed shapes
Contributing
Contributions of all kinds are welcome. These could be suggestions, issues, bug fixes, documentation improvements, or new features.
For more details see the contribution guidelines.
License
This Python module was created by Peter Grønbæk Andersen and is licensed under GNU GPL v3.
Metadata
Release files for shapeio 0.5.0b4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| shapeio-0.5.0b4.tar.gz | 59.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| shapeio-0.5.0b4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 146.3 kB
Release files / shapeio-0.5.0b4.tar.gz
| Download URL | shapeio-0.5.0b4.tar.gz |
|---|---|
| Size | 59.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
66bf8d1131544198afa4345c0f9e99dac9f89bfce0d18cf3b263b1ebe2db0cae
|
|
BLAKE2b-256 checksum How to use checksums |
dec82c86523bd5472a056f93fac1e8e0d838453068a8e05f701fcda3b5ae1016
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / shapeio-0.5.0b4-py3-none-any.whl
| Download URL | shapeio-0.5.0b4-py3-none-any.whl |
|---|---|
| Size | 87.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
252174d22b2bd8d183737f7446c1e2103c4dc60ab7a20fed4cbe574d1e18bf6c
|
|
BLAKE2b-256 checksum How to use checksums |
93e65410b5553764d78bbeda5d15a036793862c67b8a7ee6414348abbde19221
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|