Command line interface for Karrio
Project description
Karrio CLI Tools
This folder contains CLI tools for the Karrio project.
Codegen
The codegen command provides utilities for code generation, particularly for transforming JSON schemas into Python code using jstruct.
Transform
The transform command converts Python code generated by quicktype (using dataclasses) into code that uses attrs and jstruct decorators.
# Transform from stdin to stdout
cat input.py | karrio codegen transform > output.py
# Transform from file to file
karrio codegen transform input.py output.py
# Transform from file to stdout
karrio codegen transform input.py
# Disable appending 'Type' to class names
karrio codegen transform input.py output.py --no-append-type-suffix
The transform command makes the following changes:
- Replaces
from dataclasses import dataclasswith explicit imports:import attr,import jstruct,import typing - Removes any
from typing import ...lines entirely - Replaces
@dataclasswith@attr.s(auto_attribs=True) - Appends 'Type' to all class names (unless they already end with 'Type') by default
- Replaces complex type annotations with jstruct equivalents
- Ensures there are no duplicate import statements
Generate
The generate command generates Python code with jstruct from a JSON schema file using quicktype.
# Generate Python code with jstruct from a JSON schema
karrio codegen generate --src=schema.json --out=output.py
# Specify Python version
karrio codegen generate --src=schema.json --out=output.py --python-version=3.8
# Generate without --just-types
karrio codegen generate --src=schema.json --out=output.py --just-types=false
# Disable appending 'Type' to class names
karrio codegen generate --src=schema.json --out=output.py --no-append-type-suffix
Create Tree
The create-tree command generates a Python code tree from a class definition. It's useful for visualizing the structure of complex nested objects and generating initialization code templates.
# Generate a tree for a class
karrio codegen create-tree --module=karrio.schemas.allied_express.label_request --class-name=LabelRequest
# Generate a tree with a module alias
karrio codegen create-tree --module=karrio.schemas.allied_express.label_request --class-name=LabelRequest --module-alias=allied
Example output:
LabelRequestType(
bookedBy=None,
account=None,
instructions=None,
itemCount=None,
items=[
ItemType(
dangerous=None,
height=None,
itemCount=None,
length=None,
volume=None,
weight=None,
width=None,
)
],
jobStopsP=JobStopsType(
companyName=None,
contact=None,
emailAddress=None,
geographicAddress=GeographicAddressType(
address1=None,
address2=None,
country=None,
postCode=None,
state=None,
suburb=None,
),
phoneNumber=None,
),
jobStopsD=JobStopsType(...),
referenceNumbers=[],
serviceLevel=None,
volume=None,
weight=None,
)
Migrating carrier connector generate scripts
To migrate carrier connector generate scripts to use the new codegen command, run:
python karrio/modules/cli/commands/migrate_generate_scripts.py /path/to/karrio/workspace
This will update all generate scripts in the carrier connectors to use the new karrio codegen command.
JStruct Overview
JStruct is a Python library for nested object models that offers serialization and deserialization into Python dictionaries. It leverages the attrs library to define structs without boilerplate.
Here's an example of the transformed code:
import attr
import jstruct
import typing
@attr.s(auto_attribs=True)
class PersonType:
first_name: typing.Optional[str] = None
last_name: typing.Optional[str] = None
@attr.s(auto_attribs=True)
class RoleModelsType:
scientists: typing.Optional[typing.List[PersonType]] = jstruct.JList[PersonType]
For more information, see the JStruct README.
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 Distributions
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 karrio_cli-2026.1.19-py3-none-any.whl.
File metadata
- Download URL: karrio_cli-2026.1.19-py3-none-any.whl
- Upload date:
- Size: 97.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b49b26820b33f15300033cda036a026dec862057fa39b06ce248b6328a37d233
|
|
| MD5 |
541012405bb985cdffe09c63d21679fb
|
|
| BLAKE2b-256 |
e1ed212c5a8657c3f4fd65c731373bfdad3d2c3e46ec57393157d7d31a737636
|