Skip to main content

A Python library for interacting with the MyWebLog API

Project description

pyMyweblog Python Library

pyMyweblog is a Python library for interacting with the MyWebLog API, designed to fetch objects and bookings for aviation-related data. It is intended for use in Home Assistant integrations or other Python applications requiring access to MyWebLog services.

Installation

Install the library via pip:

pip install pyMyweblog

Alternatively, for local development, clone the repository and install it in editable mode:

git clone https://github.com/faanskit/pyMyweblog.git
cd pyMyweblog
pip install -e .

Project Structure

  • pyMyweblog/ — Main package, contains the API client (client.py).
  • scripts/myweblog.py — Interactive CLI utility for querying MyWebLog API.
  • tests/test_client.py — Unit tests for the API client.

Prerequisites

To use the library or CLI, you need:

  • A valid MyWebLog username and password.
  • A valid App Secret (not app_token) for the MyWebLog API.

Set these as environment variables:

  • MYWEBLOG_USERNAME
  • MYWEBLOG_PASSWORD
  • APP_SECRET

Usage

Interactive CLI Utility

You can use the interactive CLI to fetch objects, bookings, balance, transactions, and flight logs:

python -m scripts.myweblog

You will be prompted to select an operation and, for bookings, to select an airplane. Make sure the required environment variables are set or exported before running.

Booking CLI Utility (scripts/booking_cli.py)

This script provides an interactive command-line interface for managing airplane bookings via the MyWebLog API.

Features:

  • View available airplanes
  • Create new bookings with confirmation prompts
  • Delete your own bookings with confirmation prompts
  • User-friendly and structured output

How to Run:

python -m scripts.booking_cli

Requirements:

  • Environment variables must be set: MYWEBLOG_USERNAME, MYWEBLOG_PASSWORD, APP_SECRET
  • The questionary package must be installed for interactive prompts:
pip install questionary

Usage Flow:

  • On start, you will be welcomed and asked to select an airplane
  • You can view, create, or delete bookings for the selected airplane
  • All critical actions (creation/deletion) require confirmation before proceeding
  • Exit the CLI at any time by selecting "Exit" from the menu

Library Usage: MyWebLogClient

You can also use the API client in your own Python code:

from pyMyweblog.client import MyWebLogClient
import asyncio
import os

async def main():
    client = MyWebLogClient(
        username=os.getenv("MYWEBLOG_USERNAME"),
        password=os.getenv("MYWEBLOG_PASSWORD"),
        app_token=None,  # Will be fetched using APP_SECRET
    )
    await client.obtainAppToken(os.getenv("APP_SECRET"))
    objects = await client.getObjects()
    print(objects)
    await client.close()

asyncio.run(main())

Testing

Unit tests are located in tests/test_client.py and use the unittest framework. To run all tests:

python -m unittest discover tests

You can also run a specific test file:

python -m unittest tests.test_client

Requirements

For development and running tests, install all dependencies (including test and CLI requirements):

pip install -e .[dev]

If you only want to use the CLI utility, you must also install questionary:

pip install questionary

Development

Setting Up the Development Environment

  1. Clone the repository:

    git clone https://github.com/faanskit/pyMyweblog.git
    cd pyMyweblog
    
  2. Create and activate a virtual environment:

    python -m venv venv
    # On Unix/macOS:
    source venv/bin/activate
    # On Windows:
    .\venv\Scripts\activate
    
  3. Install dependencies:

    pip install -e .[dev]
    
  4. Format and lint your code:

    black .
    flake8 .
    
  5. Run unit tests:

    python -m unittest discover tests
    

Modifying the Code

  • The main API client is in pyMyweblog/client.py.
  • Add or update methods in MyWebLogClient for additional API endpoints as needed.
  • The CLI utility is in scripts/myweblog.py and can be extended for more interactive features.

CI/CD and Publishing to PyPI and TestPyPI

This project uses GitHub Actions to automatically build and publish the package to TestPyPI and PyPI. Two separate workflows are configured:


🔁 Publishing to TestPyPI

This workflow runs on every push to main if the commit message contains [dev-release].

How to trigger a TestPyPI release:

  1. Update the version in pyproject.toml
    Use a development version (ending in .devN), for example:

    version = "0.2.0.dev1"
    
  2. Commit and push with a trigger message:

    git add pyproject.toml
    git commit -m "test release 0.2.0.dev1 [dev-release]"
    git push origin main
    
  3. The workflow will run and upload the package to:
    https://test.pypi.org/project/pyMyweblog


🚀 Publishing to PyPI (Production)

This workflow runs only when a GitHub Release is published. Use this for stable releases (i.e., versions without .dev).

How to publish a production release:

  1. Update the version in pyproject.toml, for example:

    version = "0.2.0"
    
  2. Commit and push:

    git add pyproject.toml
    git commit -m "release 0.2.0"
    git push origin main
    
  3. Create a GitHub Release:

    • Go to Releases
    • Click "Draft a new release"
    • Tag: v0.2.0
    • Title/message: Release 0.2.0
    • Click "Publish release"
  4. The workflow will run and upload the package to:
    https://pypi.org/project/pyMyweblog


🔐 API Tokens

To enable publishing from CI/CD, you need to configure the following GitHub Secrets:

  • TEST_PYPI_API_TOKEN – from TestPyPI
  • PYPI_API_TOKEN – from PyPI

Add these under:
GitHub Repo → Settings → Secrets and variables → Actions → New repository secret

Contributing

Contributions are welcome! Please submit issues or pull requests to the GitHub repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.

For support, contact the maintainer at [marcus.karlsson@usa.net].

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

pymyweblog-0.6.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

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

pymyweblog-0.6.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file pymyweblog-0.6.0.tar.gz.

File metadata

  • Download URL: pymyweblog-0.6.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pymyweblog-0.6.0.tar.gz
Algorithm Hash digest
SHA256 5ec1554a9e436f5a6f3a9c5616388444020635add712fa5b86342b18533fdc6c
MD5 aacd2271ddf687899641d2c0b52fd0cb
BLAKE2b-256 532a567a6f647f9a7091a87aa3e09b898b82729ee50d7d913cff93019eb3834c

See more details on using hashes here.

File details

Details for the file pymyweblog-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: pymyweblog-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pymyweblog-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 baf719527374ab974f9506638f2250787bdba5aa1b3b5e1bc6e07ff207931f85
MD5 0c26bc9c72f3d2ff320052b0d48b0a25
BLAKE2b-256 7330536cfdb66fbbd16acdec9195601901bd71cba4cfe57fc73909b785b53a61

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