Skip to main content

A FastAPI-based API for managing the Meridian 59 server.

Project description

Meridian 59 API or m59api

This is a FastAPI-based API for managing a Meridian 59 server.


Configuration

Before running the application, you need to set the DISCORD_WEBHOOK_URL environment variable. This variable is used to send messages to Discord.

On Windows (Command Prompt or PowerShell):

set DISCORD_WEBHOOK_URL=https://your-discord-webhook-url

On macOS/Linux (bash/zsh):

export DISCORD_WEBHOOK_URL=https://your-discord-webhook-url

With Docker:

docker run --rm -it \
  -e DISCORD_WEBHOOK_URL=https://your-discord-webhook-url \
  -p 5959:5959 -p 8000:8000 -p 9998:9998 \
  m59-linux-test

Tip: Never commit secrets (like webhooks or API keys) to your repository. Always use environment variables or a .env file (with python-dotenv) for local development.


Running m59api

1. Running as a PyPI-installed Package

If you installed m59api via pip, you can run it using:

m59api --host 127.0.0.1 --port 8000 --reload

This launches the server using the CLI entry point defined in the package.

2. Running from Source (Development Mode)

If you cloned this repository and installed the dependencies manually, you can start the FastAPI server using:

uvicorn m59api.main:app --reload --log-level debug

This is useful for development and testing.

3. Running with Docker

docker run --rm -it \
  -e DISCORD_WEBHOOK_URL=https://your-discord-webhook-url \
  -p 5959:5959 -p 8000:8000 -p 9998:9998 \
  m59-linux-test

Features

  • FastAPI routes for server management in api.py
  • Connects to the BlakSton server maintenance port
  • Example API endpoints:
    • GET /api/v1/admin/who
    • POST /api/v1/admin/send-users

Why

  • Enable modern web-based management interface for blakserv
  • Provide secure, RESTful API access to server functions
  • Allow external tools/services to interact with the server

Technical Flow

FastAPI Client -> FastAPI Routes -> Maintenance Port -> Blakserv
   (HTTP)          (api.py)       (TCP Socket)         (C Core)

[Web Client] --HTTP--> [FastAPI Router] 
                          |
                          v
                    [Maintenance Port] 
                          |
                          v
                        Blakserv

Implementation Details

FastAPI Router (api.py):

  • REST endpoint definitions
  • JSON response formatting
  • Maintenance port command handling

Maintenance Client (maintenance.py):

  • TCP socket connection to BlakSton server maintenance port
  • Command sending and response handling

Server Configuration

Add the following to the blakserv.cfg in the server running directory:

[Socket]             
MaintenancePort      9998
MaintenanceMask      0.0.0.0

API Documentation


Testing Endpoints

curl -X GET "http://127.0.0.1:8000/api/v1/admin/who"
curl -X GET "http://127.0.0.1:8000/api/v1/admin/status"
curl -X GET "http://127.0.0.1:8000/api/v1/admin/memory"
curl -X POST "http://127.0.0.1:8000/api/v1/admin/send-users?message=Hello"

Security & Best Practices

  • Never commit secrets (webhooks, API keys, passwords) to your repository.
  • Use environment variables or a .env file (with python-dotenv) for local development.
  • Use --reload only for development, not in production.
  • Always test your app in a production-like environment before deployment.

Installation

1. Install dependencies

pip install -r requirements.txt

(Or use Poetry, see below)

2. Run the server:

uvicorn m59api.main:app --reload

3. Open API documentation:


CLI Arguments (cli.py)

Command-Line Arguments:

--host: Allows the user to specify the host (e.g., 0.0.0.0 for external access).
--port: Allows the user to specify the port (e.g., 8080).
--reload: Enables auto-reload for development.
--log-level: Sets the logging level (e.g., debug, info, warning).

Default Values:

If no arguments are provided, the app will run on 127.0.0.1:8000 with info log level and no auto-reload.

Customizable:

Users can override the defaults by providing arguments when running the m59api command.

Use --reload only in development:

It’s a great tool for speeding up development but should not be used in production.

Use Environment-Specific Configurations:

Use environment variables or configuration files to differentiate between development and production environments. For example:

export ENV=development
m59api --reload

Test Without --reload Before Deployment:

Always test your app in a production-like environment (without --reload) to ensure it behaves as expected.


License

Meridian 59 is open-source. See LICENSE for details.

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

m59api-0.1.0.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

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

m59api-0.1.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file m59api-0.1.0.tar.gz.

File metadata

  • Download URL: m59api-0.1.0.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for m59api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 de44b17d73897e7d9fbe0cd205c60e15adac2cf108068ca31e6214afe8176af8
MD5 5c67c9f597876f81129c24255061f962
BLAKE2b-256 da8649638708258334d5f7a4d14dd8bdc0e43ad2f4086cbb5e2515e1bb2761dd

See more details on using hashes here.

File details

Details for the file m59api-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: m59api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for m59api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2672e158dfe41b38e97d68a31f7b9a1e40d0f25102c616d28c888cb58576e827
MD5 2eefd2014a849f5825b222a4a3c4f2a0
BLAKE2b-256 338066543400f2ae6eb9ecfceed47ecebb9485f3de21482aaa9a5b75c73c4c2a

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