Skip to main content

An http ASCOM Alpaca server written in python.

Project description

python-alpaca-server

This is an easy to use Python server for ASCOM Alpaca. It can be run on any system that running Python 3.12 or higher, including a Raspberry Pi. This allows you to easily create new ASCOM Alpaca devices.

Nothing complicated here, just create a new class that implements your logic and inherits from one of the base device classes.

Then start up a new AlpacaServer. The server automatically enables discovery as well.

Example

pip install python-alpaca-server

Edit app.py

from typing import List

from python_alpaca_server.app import AlpacaServer, Description
from python_alpaca_server.devices.safetymonitor import SafetyMonitor
from python_alpaca_server.errors import NotImplementedError
from python_alpaca_server.request import ActionRequest, CommandRequest, CommonRequest, PutConnectedRequest

# Inherit from the base SafetyMonitor class, and implement the methods.
class MySafetyMonitor(SafetyMonitor):
    def __init__(self, unique_id: str):
        super().__init__(unique_id)
        self._connected = False

    def put_action(self, req: ActionRequest) -> str:
        raise NotImplementedError(req)

    def put_command_blind(self, req: CommandRequest) -> None:
        raise NotImplementedError(req)

    def put_command_bool(self, req: CommandRequest) -> bool:
        raise NotImplementedError(req)

    def put_command_string(self, req: CommandRequest) -> str:
        raise NotImplementedError(req)

    def get_connected(self, req: CommonRequest) -> bool:
        return self._connected

    def put_connected(self, req: PutConnectedRequest) -> None:
        self._connected = req.Connected

    def get_description(self, req: CommonRequest) -> str:
        return "My Description"

    def get_driverinfo(self, req: CommonRequest) -> str:
        return "My Driver Info"

    def get_driverversion(self, req: CommonRequest) -> str:
        return "0.1.0"

    def get_interfaceversion(self, req: CommonRequest) -> int:
        return 1

    def get_name(self, req: CommonRequest) -> str:
        return "MySafetyMonitor"

    def get_supportedactions(self, req: CommonRequest) -> List[str]:
        return []

    def get_issafe(self, req: CommonRequest) -> bool:
        if not self._connected:
            return False

        # TODO: Check something to see if we are safe to observe. Return True if safe.
        return False


def get_server_description() -> Description:
    return Description(
        ServerName="MyServer",
        Manufacturer="MyManufacturer",
        ManufacturerVersion="0.1.0",
        Location="MyLocation",
    )


if __name__ == "__main__":
    import uvicorn

    port = 8000

    # Choose a unique ID to pass into MySafetyMonitor. This ID should stay the same
    # across server restarts.
    svr = AlpacaServer(get_server_description, [MySafetyMonitor("other")])

    # Create a FastAPI application we can attach to uvicorn or any other WSGI server.
    app = svr.create_app(port)

    try:
        uvicorn.run(app, host="0.0.0.0", port=port)
    except KeyboardInterrupt:
        pass

Run

python app.py

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

python_alpaca_server-1.0.3.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

python_alpaca_server-1.0.3-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file python_alpaca_server-1.0.3.tar.gz.

File metadata

  • Download URL: python_alpaca_server-1.0.3.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.11.1 Darwin/23.6.0

File hashes

Hashes for python_alpaca_server-1.0.3.tar.gz
Algorithm Hash digest
SHA256 85105ff30061931d300bec8d5d8c666c8e1f72c305ba61f58e444ebd427ca85b
MD5 85cd4fcc6b02b2e1c269fa42a93a7107
BLAKE2b-256 927c147c65e1ff2bc1c7a377286e8ebe6a8ffcff91df44500d954b28d659b99e

See more details on using hashes here.

File details

Details for the file python_alpaca_server-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for python_alpaca_server-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0c48b3a34a19a2187db874006313d3d63247bcdbaa72166f339de46952dbd5bc
MD5 08cac9466d393acec804e4819183b6d9
BLAKE2b-256 34867d0ed48688738c3e19878a4a41ea0c11c65d2422f1fab5a129f16eef2d97

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