Skip to main content

MSFS SimConnect wrapper for Python

Project description

py-simcon

This is a Python wrapper for SimConnect library which is used to talk to Microsoft Flight Simulator. This wrapper provides natural pythonic interface. It can be used in both synchronous and asynchronous (asyncio) applications. In both cases it is thread safe.

Features

  • Listen to system events (aircraft loaded, game paused, etc)
  • Receive data updates
  • Async and sync interfaces, which can work together simultaneously

Examples

Conventional (synchronous)

import pprint

from simcon import Sim, DataField, PERIOD


with Sim("asd") as sim: 
    data_request = sim.request_data_on_sim_object(
        [
            DataField("Plane latitude", "degrees"),
            DataField("Plane longitude", "degrees"),
            DataField("Plane altitude", "feet"),
            DataField("GPS ground true track", "degrees"),
            DataField("GPS ground speed", "knots"),
            DataField("Zulu time", "seconds"),
        ],
        PERIOD.SIMCONNECT_PERIOD_SECOND,
    )
    count = 0
    for data in data_request:
        pprint.pprint(data)
        count += 1
        if count >= 10:
            break

Result:

{'GPS ground speed': 97.83114326014487,
 'GPS ground true track': 307.4598039853386,
 'Plane altitude': 8501.684970335986,
 'Plane latitude': 39.3924225392898,
 'Plane longitude': -125.57142850592173,
 'Zulu time': 3287.369384765625}
{'GPS ground speed': 97.83704928992589,
 'GPS ground true track': 307.45556123353225,
 'Plane altitude': 8501.840396854732,
 'Plane latitude': 39.39269706474836,
 'Plane longitude': -125.57189141562071,
 'Zulu time': 3288.369384765625}
...

Asynchronous (asyncio):

import asyncio
import pprint

from simcon import Sim, DataField, PERIOD


async def show_data():
    async with Sim("asd") as sim: 
        data_request = sim.request_data_on_sim_object(
            [
                DataField("Plane latitude", "degrees"),
                DataField("Plane longitude", "degrees"),
                DataField("Plane altitude", "feet"),
                DataField("GPS ground true track", "degrees"),
                DataField("GPS ground speed", "knots"),
                DataField("Zulu time", "seconds"),
            ],
            PERIOD.SIMCONNECT_PERIOD_SECOND,
        )
        count = 0
        async for data in data_request:
            pprint.pprint(data)
            count += 1
            if count >= 10:
                break

asyncio.run(show_data())

Results will be the same as in the example above

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

simcon-0.1.0.tar.gz (12.6 kB view hashes)

Uploaded Source

Built Distributions

simcon-0.1.0-cp39-cp39-win_amd64.whl (494.2 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

simcon-0.1.0-cp38-cp38-win_amd64.whl (495.5 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

simcon-0.1.0-cp37-cp37m-win_amd64.whl (486.1 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

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