Skip to content

adamkornafeld/mygls-python

Repository files navigation

mygls-rest-client

mygls-rest-client is a python client for the MyGLS REST API to create printable shipping labels.

Before you can start interacting with the MyGLS REST API, you need an agreement with GLS. If you don’t have the required MyGLS login credentials please contact GLS.

Motivation

The API development team of GLS has decided to release sample code for C#, PHP, JAVA.

This project adds Python to mix.

Under the hood

mygls-rest-client uses the requests library to fetch data via the MyGLS API. A couple design decisions to be aware of that this client library has no influence on:

  • all API endpoints use the POST HTTP verb
  • all model properties use upper camel case naming

Install

MyGLS Rest Client is published in the PyPi package repository.

pip install mygls-rest-client

Basic usage

  1. Create a GLS instance:

     from gls import GLS
    
     client_number = 100123456
     username = "user@gls.hu"
     password = "secret"
     
     gls = GLS(client_number, username, password)
    

    1.1. Configure settings

     from gls import Settings, CountryCode
    
     gls = GLS(client_number, username, password, Settings(country=CountryCode.HR, test=True))
    

    Consult settings.py for supported countries.

  2. Create a parcel label:

     from datetime import datetime
     from gls import Address, Parcel
    
     ADDRESS = {
         "City": "Budapest",
         "ContactEmail": "info@bme.hu",
         "ContactName": "Dr. Sztoczek József",
         "ContactPhone": "+36 1 463-1111",
         "CountryIsoCode": "HU",
         "HouseNumber": "3",
         "Name": "Budapesti Műszaki és Gazdaságtudományi Egyetem",
         "Street": "Műegyetem rkp.",
         "ZipCode": "1111",
         "HouseNumberInfo": "",
     }
    
     parcel = gls.create_parcel(
         pickup_from = Address(**ADDRESS),
         deliver_to = Address(**ADDRESS),
         pickup_date = datetime.today(),
         reference = "REF-123",
         count = 1
     )
    
     pdf_absolute_path = "~/label.pdf"
     parcel_ids = gls.print_labels(
         pdf_absolute_path, [parcel],
     )
    
  3. Look up parcels by print date:

     from gls import ParcelResponse
     from datetime import datetime
    
     parcels: ParcelResponse = gls.get_parcels(
         print_from=datetime.today(),
         print_to=datetime.today(),
     )
    
  4. Get printed labels:

     from gls import PrintedLabelsResponse
    
     labels: PrintedLabelsResponse = gls.get_printed_labels(parcel_ids=[10023456])
    
  5. Delete labels:

     from gls import DeleteLabelsResponse
    
     parcel_ids = [10023456]
     result: DeleteLabelsResponse = gls.delete_labels(parcel_ids)
    

Sample Output

Here is an example of how the created label would look like in the saved PDF:

Label

Contributions

Contributions are welcome, please submit a Pull Request.

Development

I use pipenv to manage the development environment. Dependencies are listed in setup.cfg.

pip install pipenv
cd mygls-python
pipenv shell
pipenv install -e ".[dev,test]"

Reference

GLS is a trademark and brand of General Logistics Systems Germany GmbH & Co.

About

Python client of MyGLS API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages