Skip to main content

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 dataclass with explicit imports: import attr, import jstruct, import typing
  • Removes any from typing import ... lines entirely
  • Replaces @dataclass with @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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

karrio_cli-2026.1.4-py3-none-any.whl (148.3 kB view details)

Uploaded Python 3

File details

Details for the file karrio_cli-2026.1.4-py3-none-any.whl.

File metadata

  • Download URL: karrio_cli-2026.1.4-py3-none-any.whl
  • Upload date:
  • Size: 148.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for karrio_cli-2026.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4a75d55c900b5dd1ec80fa905ad8b8962fc2ae9394191855e5341555e859e9aa
MD5 6c0c3e900bbbb1cab3c7c9248b692a43
BLAKE2b-256 d37545ed97d39a71d70da0c8337e7f6f1aa347aec26532e809dc617aae4ee9ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page