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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pymyweblog-0.3.2.tar.gz
  • Upload date:
  • Size: 10.7 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.2.tar.gz
Algorithm Hash digest
SHA256 26c07d54a003b26fb4a03b6be8e8a9a01622b7cfb0007bb01af729f2604e4aa0
MD5 b084fc752495d736c84f95a0f95ca778
BLAKE2b-256 272520980acf5623fa88f57eebf48d2e248d46e4dce8432852c82275a721d1f0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pymyweblog-0.3.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0dfaef777c1fd2a5d3e885ddef7af88c6492d53c88e1a8fbcc52bcad92d5cfdd
MD5 1b7fb088f0b68182b2eb4e666b28fc3c
BLAKE2b-256 85f1f20e6defaa10384d5c5b151d4d826f927f633ee67d6877f4d2a369f7c061

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