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 .

Prerequisites

To use the library, you need:

  • A valid MyWebLog username and password.
  • A valid app_token for MyWebLog Mobile API

Usage

The MyWebLogClient class provides methods to interact with the MyWebLog API, such as fetching objects and bookings.

Example: Fetching Objects

from pyMyweblog.client import MyWebLogClient

# Initialize the client
client = MyWebLogClient(
    username="your_username",
    password="your_password",
    app_token="your_apptoken",
)

# Fetch objects
objects = client.getObjects()
print(objects)

# Close the session
client.close()

# Alternatively, use as a context manager
with MyWebLogClient(
    username="your_username",
    password="your_password",
    app_token="your_apptoken",
) as client:
    objects = client.getObjects()
    print(objects)

Example: Fetching Bookings

from pyMyweblog.client import MyWebLogClient

with MyWebLogClient(
    username="your_username",
    password="your_password",
    app_token="your_apptoken",
) as client:
    bookings = client.getBookings(mybookings=True, includeSun=True)
    print(bookings)

Testing the API

Before pushing any changes, please follow these steps to ensure everything works locally.

  1. Set environment variables (recommended for security):

    export MYWEBLOG_USERNAME="your_username"
    export MYWEBLOG_PASSWORD="your_password"
    export MYWEBLOG_APPTOKEN="your_apptoken"
    
  2. Run the test script:

    python scripts/test_get_objects.py
    

    This will fetch objects and print the API response in a formatted way using pprint.

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
    source venv/bin/activate  # On Windows: .\venv\Scripts\activate
    
  3. Install dependencies:

    pip install -e .[dev]
    

Running Tests Locally Before Pushing

To ensure your code adheres to the standards and passes tests, follow these steps before you push your changes:

  1. Install dependencies (if not already done):

    pip install -e .[dev]
    
  2. Run format and lint checks:

    • Black: Automatically formats your code to conform to Python’s PEP 8 style.

      black .
      
    • Flake8: Lints your code for style issues, such as unused imports or incorrect indentation.

      flake8 .
      
  3. Run unit tests:

    • Pytest: Run all the tests in the tests/ directory and verify they pass.
      pytest --ignore=scripts/test_get_objects.py --ignore=scripts/test_get_balance.py --ignore=scripts/test_get_bookings.py
      

    If all tests pass without errors, you're good to go!

Running Unit Tests

Unit tests are located in the tests/ directory and use unittest.

python -m unittest discover tests

Modifying the Code

  • The main API client is in pyMyweblog/client.py.
  • Update app_token and ac_id in MyWebLogClient with valid values or make them configurable.
  • Add new methods to MyWebLogClient for additional API endpoints as needed.

Running Test Scripts

Test scripts are located in the scripts/ directory and use python.

Example #1: To test the GetObjects function, you can run this script:

python -m scripts.test_get_objects

Example #2: To test the GetBalance function, you can run this script:

python -m scripts.test_get_balance

Example #3: To test the GetBookings function, you can run this script:

python -m scripts.test_get_bookings

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.3.0.tar.gz (10.6 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.3.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pymyweblog-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f968c1a20ccd0ab50132a0728607ac150e2b9f36ddfd81352f35338852e532ca
MD5 a683e3a1edf6e2c35388d4f162c24237
BLAKE2b-256 f8c993b45c3d5f91e18541877e66aa9c4d8d741a574844555c59d47a57a91cf6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pymyweblog-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b91fa6d29d1dda56f24b24587f6614cac4f67ecf57aec1d903c197dffc48661
MD5 5be76f375e73f8ec615691291151ff97
BLAKE2b-256 c5832d36aaad6484373f7da3da0fdf987fb0dcefc772bafa0e219d354e076843

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