Skip to main content

A Python library for connecting with X-Plane 12 via UDP

Project description

X-Plane UDP

The goal of this package is to allow for high-level, abstract communication with X-Plane via UDP without having to configure the connections manually. It is verified to work with X-Plane 12.4.0.

Installation

To install the package, simply type in your terminal

python3 -m pip install pyxpudp

Python API Documentation

The central point of the library is the XPConnector X-Plane connection object. It can be used either by normally creating the object and calling .close() to terminate the connection, or you can use the with construction, as in the example file. At the moment, it implements a few basic methods, as described below. All of the snippets should be functional in the default C172.

To get the object, simply call

with XPConnector():
    pass

Of course, it's allowed to specify :

  • host_ip (default 'localhost')
  • send_port (port, to which the messages will be sent, default 49000)
  • receive_port (port, that will receive messages from X-Plane, default 49001)
  • listen_freq (frequency of checking for new messages from X-Plane)

Send command

Execute a command.

with XPConnector() as conn: 
    conn.send_command('sim/flight_controls/flaps_down')

Set dataref

Pass the dataref name, then value. Then, optionally the dataref type.

with XPConnector() as conn:
    conn.set_dataref('sim/cockpit/autopilot/heading_mag', 180)

Subscribe to dataref

Subscribing to dataref allows you to fetch its value later on. Fetching without previous subscription automatically subscribes with the frequency of 1Hz. Pass the dataref and then, optionally, the frequency, at which X-Plane is to send the data. To unsubscribe, send the subscription message with freq=0.

with XPConnector() as conn:
    conn.subscribe_to_dataref('sim/cockpit/autopilot/heading_mag')

Get the value of a single dataref

To get the value of a single dataref, pass the dataref name. Optionally you can pass the is_blocking parameter - if it's True (default) the code will block until the dataref is received. If it's False, the requested dataref will return None if it has not been received yet. If the dataref hasn't been subscribed to before, it'll automatically subscribe at the frequency of 1Hz. Note, that in this case, the is_blocking is forced to be True.

with XPConnector() as conn:
    value = conn.get_dataref(
        'sim/cockpit/autopilot/heading_mag',
        is_blocking=False
    )

Subscribe to multiple datarefs

This function is a simple way to subscribe to multiple datarefs. Pass the dataref names and then, optionally, the frequency (keyword argument).

with XPConnector() as conn:
    conn.subscribe_to_datarefs(
        'sim/cockpit/autopilot/heading_mag',
        'sim/cockpit/radios/transponder_code',
        freq=2 
    )

Get multiple datarefs

This function is a simple way to subscribe to multiple datarefs. Pass the dataref names and then, optionally, the is_blocking value (keyword argument). The last argument is documented in the get_dataref section.

with XPConnector() as conn:
    received_datarefs = conn.get_datarefs(
        'sim/cockpit/autopilot/heading_mag',
        'sim/cockpit/radios/transponder_code',
        is_blocking=False
    )

Close the connection

If not using the with construction, close the connection manually. Otherwise, the background threads will not terminate.

conn = XPConnector()
conn.close()

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

pyxpudp-0.0.1.1.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyxpudp-0.0.1.1-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file pyxpudp-0.0.1.1.tar.gz.

File metadata

  • Download URL: pyxpudp-0.0.1.1.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for pyxpudp-0.0.1.1.tar.gz
Algorithm Hash digest
SHA256 951fe81b606f835108562a3dc1c9f43ce8ee6d7d406964630d9806129de34230
MD5 0fc6592346a631088c29c7af07c34799
BLAKE2b-256 621a0da0cd514b5225c9939bcc661290d254b41b30ada6568f52600c5783387e

See more details on using hashes here.

File details

Details for the file pyxpudp-0.0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyxpudp-0.0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for pyxpudp-0.0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6961f516338f94fe0c321a4eb8c70a238a971c65d8f0f308e66cd6399e3c9ccf
MD5 a89b97e8d81b6babccfa523371f0c02b
BLAKE2b-256 bc5601e4a99acffabd31d5571c26996ffb7901f0abfb2973ab7bf9f9f52447e9

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