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.5.1.tar.gz (12.4 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.5.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pymyweblog-0.5.1.tar.gz
Algorithm Hash digest
SHA256 08f99a9c17b748c963d2972f928c142104f4cbfeae615254a3b64c033a3dd8e4
MD5 17261e80b6cdd1eceee30cc88e9dee6a
BLAKE2b-256 9b1ae4d717a7d15982cf4cba990ef0b7914e5ffa2099315545b7124773159142

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pymyweblog-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 95bb8cd509258d71a90cea3d73d77b62114207b2522fcd4d8877b27009aeaf5e
MD5 e816e5f7bd9b7330680cc460948c8f26
BLAKE2b-256 2e50f0a0e450f9383ba551b035aaa9785e92cc981b113c1ed76759c391926f78

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