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_tokenfor 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.
-
Set environment variables (recommended for security):
export MYWEBLOG_USERNAME="your_username" export MYWEBLOG_PASSWORD="your_password" export MYWEBLOG_APPTOKEN="your_apptoken"
-
Run the test script:
python scripts/test_get_objects.pyThis will fetch objects and print the API response in a formatted way using
pprint.
Development
Setting Up the Development Environment
-
Clone the repository:
git clone https://github.com/faanskit/pyMyweblog.git cd pyMyweblog
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate
-
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:
-
Install dependencies (if not already done):
pip install -e .[dev]
-
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 .
-
-
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!
- Pytest: Run all the tests in the
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_tokenandac_idinMyWebLogClientwith valid values or make them configurable. - Add new methods to
MyWebLogClientfor 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:
-
Update the version in
pyproject.toml
Use a development version (ending in.devN), for example:version = "0.2.0.dev1"
-
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
-
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:
-
Update the version in
pyproject.toml, for example:version = "0.2.0"
-
Commit and push:
git add pyproject.toml git commit -m "release 0.2.0" git push origin main
-
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"
-
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:
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymyweblog-0.3.1.tar.gz.
File metadata
- Download URL: pymyweblog-0.3.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a82fe7c9b7e6a5b5c7fc5fc5944c39488d1a242b114af39ecfa1257789bddde6
|
|
| MD5 |
4410e497188628508bb1578917fa32a7
|
|
| BLAKE2b-256 |
6622573a0e28f003193437e3c4f3864b9e79f045ea240e62b069c61ee4e432ce
|
File details
Details for the file pymyweblog-0.3.1-py3-none-any.whl.
File metadata
- Download URL: pymyweblog-0.3.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cea41a959d44b9eafec33195f806591cb10ae592da303d01001ac6d84f496f64
|
|
| MD5 |
beef84245c1c57e367a21f5ee911b586
|
|
| BLAKE2b-256 |
2055517a2a486d3fd10654916128bd4e2a28685564de8075951fd80f64dcdb93
|