{"id":22122607,"url":"https://github.com/thorgate/pywaybiller","last_synced_at":"2025-03-24T07:23:09.768Z","repository":{"id":205980831,"uuid":"715510878","full_name":"thorgate/pywaybiller","owner":"thorgate","description":"Python client for waybiller.com external API","archived":false,"fork":false,"pushed_at":"2025-03-11T11:31:02.000Z","size":199,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-11T12:31:14.970Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thorgate.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-07T09:41:54.000Z","updated_at":"2025-03-11T11:31:08.000Z","dependencies_parsed_at":"2025-03-11T12:36:06.008Z","dependency_job_id":null,"html_url":"https://github.com/thorgate/pywaybiller","commit_stats":null,"previous_names":["thorgate/pywaybiller"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thorgate%2Fpywaybiller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thorgate%2Fpywaybiller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thorgate%2Fpywaybiller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thorgate%2Fpywaybiller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thorgate","download_url":"https://codeload.github.com/thorgate/pywaybiller/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245225019,"owners_count":20580454,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-01T15:26:41.962Z","updated_at":"2025-03-24T07:23:09.754Z","avatar_url":"https://github.com/thorgate.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyWaybiller\n\n## Installation\n\n```shell\npoetry add pywaybiller\n```\n\n## Usage\n\n### Get all waybills\n\n```python\nimport pywaybiller\nimport datetime\n\nend_date = datetime.datetime.now()\nstart_date = end_date - datetime.timedelta(days=7)\n\n\nclient = pywaybiller.WaybillerClient(\n    api_key=\"xxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\n    host=\"https://staging.app.waybiller.com/external-api\",\n)\n\nfor waybill in client.waybills.all(\n    dispatcher_timestamp__gt=start_date.strftime(\"%Y-%m-%dT%H:%M:%S\"),\n    dispatcher_timestamp__lt=end_date.strftime(\"%Y-%m-%dT%H:%M:%S\"),\n):\n    print(waybill)\n```\n\nAll endpoint uses generator. It will load data page by page, querying later pages only if you need them.\n\n## Saving data for later\n\n```python\nimport pywaybiller\nfrom pywaybiller.openapi_client import ExternalAPIVehicle\nfrom my_project.models import SomeDjangoModel\n\ninstance = SomeDjangoModel()\n# Sanitize data for serialization for later use\ninstance.json_field = pywaybiller.WaybillerClient.sanitize_for_serialization(\n    ExternalAPIVehicle(\n        id=1,\n        reg_number=\"839PVF\",\n        trailer_reg_number=\"042TST\",\n        inactive=False,\n        company_name=\"Test company\",\n        company_reg_code=\"10000042\"\n    )\n)\n\ninstance.save()\ninstance.refresh_from_db()\n\n# Rehydrate the data saved earlier\napi_model = pywaybiller.WaybillerClient.deserialize_data(\n    instance.json_field, ExternalAPIVehicle\n)\n```\n\nDeserialize data method calls pydantic from_dict internally, but hides implementation details\nthat may change in future from the code using the API client.\n\n## Updating schema and testing\n\nTo update schema from waybiller, run `make openapi`. It is possible that\nthis command will fail if waybiller schema changed significantly and the patch\ncan not be applied anymore. In this case, you will have to follow the steps\nbelow to create a new patch\n\nIt is possible that Waybiller schema is not actually compliant with the data\nthat waybiller system sends. This causes problems, as server response will\nnot validate and exception will be raised. To work around this, we patch the\nschema.\n\n### Creating new schema patch\n\nTo create a schema patch, get the fresh schema from WB and patch it with the\nexisting patch:\n```shell\nmake openapi-fetch\n# The next may fail, but then you would need to manually port existing\n# patch to the new patched schema\nmake openapi-apply-patch\n```\n\nThen, copy over the schema from `pywaybiller/openapi/waybiller_schema.json` to\n`pywaybiller/openapi/waybiller_schema-patched.json` and edit it to make it \nconsistent with what server sends (usually this involves removing validation\nfor strings to be non-empty, as the most common issue with schema is that\nserver actually sends empty strings where schema says it can not).\n\nFinally run\n```shell\nmake openapi-patch\n```\n\nThis will update schema-fixes.patch, which should be commited to the repository.\n\n### Testing with waybiller data\n\nWaybiller team can make a dump of all entities for particular endpoint into a big\njson file, so that we try to deserialize it and see if there are no validation \nerrors. As this kind of dump contains sensitive data, it is not possible to include\nit in this repository.\n\nTo perform the manual test with this data dump, use `manual_test_json_dump.py`:\n```shell\n# in Waybiller - the management command is not merged to master yet, and may be gone in future\nmake docker-manage cmd=\"external_api_export --view waybill --endpoint list\" \u003e /tmp/waybills-list.json\n\n# in pywaybiller\npoetry run python tests/manual_test_json_dump.py --filename /tmp/waybills-list.json  --skip-lines 1 --model ExternalAPIWaybillList\n```\n\nNote that you probably need to separately test list and detail endpoints, as schema is different.\n\nThis needs to be repeated for all endpoints you want to check. Currently, only waybill list and retrieve endpoints are\ntested thoroughly with both staging and production data in this way. \n\n## Credits\n\nThis project is generated with help of dockerized openapi generator: https://hub.docker.com/r/openapitools/openapi-generator-cli","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthorgate%2Fpywaybiller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthorgate%2Fpywaybiller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthorgate%2Fpywaybiller/lists"}