Linnworks API Python Client
Project description
linnworks-api-python
This is a python version of the Linnworks API https://apidocs.linnworks.net/reference/overview
We use the openapi generator https://openapi-generator.tech/ to convert the linnworks api swagger api models https://github.com/LinnSystems/PublicApiSpecs into a python package.
This creates a requests based API with pydantic types. Awesome!
This project consists of tweaks I had to make to aws auth schemes to get things working with the openapi generator client, the generator script that creates the models and a little bit of documentation. Nothing fancy.
Prerequisites
- python 3.9+
- linnworks api credentials. See the docs https://apidocs.linnworks.net/reference/setting-up
Installation
pip install linnworks-api-python
Usage
import os
from linnworks_api.generated.auth.api import AuthApi
from linnworks_api.generated.auth.models.authorize_by_application_request import AuthorizeByApplicationRequest
from linnworks_api.generated.inventory.api import InventoryApi
from linnworks_api.generated.inventory.base_client import LinnworksConfig, LinnworksClient as InventoryClient
# Mock responses
from dotenv import load_dotenv
load_dotenv()
def test_auth():
"""This is an example of how to get an auth token"""
props = AuthorizeByApplicationRequest(
ApplicationId=os.getenv("LW_CLIENT_ID"),
ApplicationSecret=os.getenv("LW_CLIENT_SECRET"),
Token=os.getenv("LW_TOKEN"),
)
auth_api = AuthApi()
response = auth_api.authorize_by_application(props)
assert isinstance(response.token, str)
def test_inventory():
"""This is an example of how to create a client and make an API call"""
inventory_client = InventoryClient(
linnworks_config=LinnworksConfig(
client_id=os.getenv("LW_CLIENT_ID"),
client_secret=os.getenv("LW_CLIENT_SECRET"),
token=os.getenv("LW_TOKEN"),
)
)
inventory_api = InventoryApi(inventory_client)
response = inventory_api.get_inventory_items_count()
assert response == 1
Development
This is a poetry project so do the normal poetry install type things to set up your environment.
We use a Makefile for build automation.
make cleanremoves the generated codemake generategenerates the schemasmake testruns unit testsmake lint-fixfixes linting issues and checks compliance with linting standards
Project Structure
.
├── Makefile - make scripts
├── README.md - this file
├── notebooks
│ └── api_test.ipynb - example usage
├── poetry.lock
├── pyproject.toml
├── PublicApiSpecs - the linnworks swagger models. A git submodule
├── scripts
│ └── generate_schemas.py - script to generate api
├── tests - unit tests. (just enough to make sure things generated without error)
└── src
└── linnworks_api
|── base_client.py - client that gets copied into each package in generated/
└── generated - the generated api files created when generate_schemas.py is run
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 linnworks_api_python-0.1.0.tar.gz.
File metadata
- Download URL: linnworks_api_python-0.1.0.tar.gz
- Upload date:
- Size: 1.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.11 Linux/6.8.0-1017-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b743aabc584e970e9fbc7ef3a2dafa2899ad3e2e108f2c794ca03f992e1b6cc2
|
|
| MD5 |
5b771ca4fdae25ffc83c09072e7b7a9c
|
|
| BLAKE2b-256 |
a1c0c2a7d0c683093a126a9dc4787c8d85a5f58f2b5f41115650d78b923a867c
|
File details
Details for the file linnworks_api_python-0.1.0-py3-none-any.whl.
File metadata
- Download URL: linnworks_api_python-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.11 Linux/6.8.0-1017-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1195360defdc56af30327a295974a270ca0dea347da54462bbcfe0b081b5d47
|
|
| MD5 |
16b856119ef3b72c51ee9529500d1e92
|
|
| BLAKE2b-256 |
8edf6c5739f4913afef203ed2fa311b265a3efac86a5af93ce3f3f8af72b4601
|