Skip to main content

PyWaybiller

Installation

poetry add pywaybiller

Usage

Get all waybills

import pywaybiller
import datetime

end_date = datetime.datetime.now()
start_date = end_date - datetime.timedelta(days=7)


client = pywaybiller.WaybillerClient(
    api_key="xxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    host="https://staging.app.waybiller.com/external-api",
)

for waybill in client.waybills.all(
    dispatcher_timestamp__gt=start_date.strftime("%Y-%m-%dT%H:%M:%S"),
    dispatcher_timestamp__lt=end_date.strftime("%Y-%m-%dT%H:%M:%S"),
):
    print(waybill)

All endpoint uses generator. It will load data page by page, querying later pages only if you need them.

Saving data for later

import pywaybiller
from pywaybiller.openapi_client import ExternalAPIVehicle
from my_project.models import SomeDjangoModel

instance = SomeDjangoModel()
# Sanitize data for serialization for later use
instance.json_field = pywaybiller.WaybillerClient.sanitize_for_serialization(
    ExternalAPIVehicle(
        id=1,
        reg_number="839PVF",
        trailer_reg_number="042TST",
        inactive=False,
        company_name="Test company",
        company_reg_code="10000042"
    )
)

instance.save()
instance.refresh_from_db()

# Rehydrate the data saved earlier
api_model = pywaybiller.WaybillerClient.deserialize_data(
    instance.json_field, ExternalAPIVehicle
)

Deserialize data method calls pydantic from_dict internally, but hides implementation details that may change in future from the code using the API client.

Updating schema and testing

To update schema from waybiller, run make openapi. It is possible that this command will fail if waybiller schema changed significantly and the patch can not be applied anymore. In this case, you will have to follow the steps below to create a new patch

It is possible that Waybiller schema is not actually compliant with the data that waybiller system sends. This causes problems, as server response will not validate and exception will be raised. To work around this, we patch the schema.

Creating new schema patch

To create a schema patch, get the fresh schema from WB and patch it with the existing patch:

make openapi-fetch
# The next may fail, but then you would need to manually port existing
# patch to the new patched schema
make openapi-apply-patch

Then, copy over the schema from pywaybiller/openapi/waybiller_schema.json to pywaybiller/openapi/waybiller_schema-patched.json and edit it to make it consistent with what server sends (usually this involves removing validation for strings to be non-empty, as the most common issue with schema is that server actually sends empty strings where schema says it can not).

Finally run

make openapi-patch

This will update schema-fixes.patch, which should be commited to the repository.

Testing with waybiller data

Waybiller team can make a dump of all entities for particular endpoint into a big json file, so that we try to deserialize it and see if there are no validation errors. As this kind of dump contains sensitive data, it is not possible to include it in this repository.

To perform the manual test with this data dump, use manual_test_json_dump.py:

# in Waybiller - the management command is not merged to master yet, and may be gone in future
make docker-manage cmd="external_api_export --view waybill --endpoint list" > /tmp/waybills-list.json

# in pywaybiller
poetry run python tests/manual_test_json_dump.py --filename /tmp/waybills-list.json  --skip-lines 1 --model ExternalAPIWaybillList

To perform the manual test by direct API calls, use manual_test_api.py:

poetry run python tests/manual_test_api.py --model ExternalAPIWaybillList --api-key 'SECRET'

Note that you probably need to separately test list and detail endpoints, as schema is different.

This needs to be repeated for all endpoints you want to check. Currently, only waybill list and retrieve endpoints are tested thoroughly with both staging and production data in this way.

Credits

This project is generated with help of dockerized openapi generator: https://hub.docker.com/r/openapitools/openapi-generator-cli

Metadata

Release files for pywaybiller 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pywaybiller 0.2.1
File Size Uploaded Provenance
pywaybiller-0.2.1.tar.gz 153.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pywaybiller 0.2.1
File Interpreter ABI Platform
pywaybiller-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 620.3 kB

Release files / pywaybiller-0.2.1.tar.gz

Download URL pywaybiller-0.2.1.tar.gz
Size 153.6 kB
Tags Source
SHA-256 checksum
How to use checksums
96cdc49c5f66d9294177088151964c4c1bac89768cc77074752da7f97c4c2a8c
BLAKE2b-256 checksum
How to use checksums
4dd0491327265bd86b99514f937d70033a371368c482fa8bb79ecf51b0d2d1fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.0 CPython/3.13.3 Linux/6.14.6-arch1-1

Release files / pywaybiller-0.2.1-py3-none-any.whl

Download URL pywaybiller-0.2.1-py3-none-any.whl
Size 466.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3039e5400d221e2956f95285d227f6121e2ba15174b4489556277edfde3840df
BLAKE2b-256 checksum
How to use checksums
3079ad595e21267aa5a8ff705ebf4c74beee909ceecebc46478f245dbfde0c5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.0 CPython/3.13.3 Linux/6.14.6-arch1-1

Security for pywaybiller 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page