Skip to main content

Kaiba

Kaiba is a data transformation tool written in Python that uses a DTL(Data Transformation Language) expressed in normal JSON to govern output structure, data fetching and data transformation.


test codecov Python Version wemake-python-styleguide


Documentation (Stable | Latest) | Source Code | Task Tracker

What is Kaiba

Kaiba is a JSON to JSON mapper. That means that we read input JSON and create output JSON. How the output is created is based on instructions from a configuration file. The configuration file governs the the output structure and tells Kaiba where in the input to find data and where to place it in the output. In addition to this Kaiba supports data transformation with data casting, regular expressions, if conditions, combination of data from multiple places and of course setting default values.

This enables you to change any input into the output you desire.

The Kaiba App

The kaiba App is currently in development

app.kaiba.tech

The app provides a user interface for creating Kaiba configurations. With the app you can map in real time easily and create the kaiba config.

The Kaiba API

The kaiba api is open for anyone to try, you send your data and the configuration and get mapped data response.

api.kaiba.tech/docs

Typical usecases

  • You GET data from api, but need to transform it for your backend system
  • POSTing data to an api that needs data on a different format than what your system produces
  • All your backends speak different language? pipe it through Kaiba
  • Customer delivers weirdly formatted data? Use Kaiba to make it sexy
  • Have CSV but need nicely structured JSON? make CSV into a JSON list and transform it with Kaiba
  • Have XML but need to change it? make it into JSON, transform it with Kaiba and then dump it to XML again.
  • Customers legacy system needs CSV. Use Kaiba to transform your nicely structured JSON data into a JSON List that can be easily dumped to CSV

Official Open kaiba Solutions

kaiba-cli, commandline interface for file to file mapping.

kaiba-api, FastAPI driven rest server that maps data with kaiba

Enterprise solutions

Coming...

Goal

The goal of this library is to make JSON to JSON transformation/mapping easy, configurable and documentable. We achieve this by using a simple but feature-rich JSON configuration which then also acts as documentation and as a contract between parties.

Why

Kaiba was born because we really dislike mapping. Documenting whatever decisions made in your code so that some product owner understands it is also no me gusto. Transforming data from one format to another is something software engineers do allmost daily... It should be easy! And documenting it shouldn't be something you have to worry about.

After the Worst POC in History we never wanted to do mapping by scripts and code again. This lead to the idea that it should be possible to create a file which governs how the structure should look and how the data should be transformed. This would then be the single source of truth and with Kaiba we have achieved this.

We believe that this will make collaboration between teams faster and easier. Use Kaiba to agree with data formats between Front-end and Back-end. Between the 3rd party system and your back-end. You can even use Kaiba for testing existing integrations ;-)

Features

  • Mapping with configuration File.
  • JSON Schema validation of the config file.
  • Structurally Transform JSON
  • Combine multiple values to one.
  • Default values
  • If statements
    • is, contains, in, not
  • Casting
    • integer, decimal, iso date
  • Regular Expressions

Contributing

Please see contribute

Installation

Package is on pypi. Use pip or poetry to install

pip install kaiba
poetry add kaiba

Introduction

Have a look at our introduction course here

Quickstart

import simplejson

from kaiba.process import process

my_config = {
    'name': 'schema',
    'array': False,
    'objects': [
        {
            'name': 'invoices',
            'array': True,
            'iterators': [
                {
                    'alias': 'invoice',
                    'path': ['root', 'invoices'],
                },
            ],
            'attributes': [
                {
                    'name': 'amount',
                    'data_fetchers': [
                        {
                            'path': ['invoice', 'amount'],
                        },
                    ],
                    'casting': {
                        'to': 'decimal',
                        'original_format': 'integer_containing_decimals',
                    },
                    'default': 0,
                },
                {
                    'name': 'debtor',
                    'data_fetchers': [
                        {
                            'path': ['root', 'customer', 'first_name'],
                        },
                        {
                            'path': ['root', 'customer', 'last_name'],
                        },
                    ],
                    'separator': ' ',
                },
            ],
            'objects': [],
        },
    ],
}

example_data = {
    'root': {
        'customer': {
            'first_name': 'John',
            'last_name': 'Smith',
        },
        'invoices': [
            {
                'amount': 10050,
            },
            {
                'amount': 20050,
            },
            {
                'amount': -15005,
            },
        ],
    },
}

mapped_data = process(example_data, my_config)

with open('resultfile.json', 'w') as output_file:
    output_file.write(simplejson.dumps(mapped_data))

contents of resultfile.json

{
    "invoices": [
        {
            "amount": 100.5,
            "debtor": "John Smith"
        },
        {
            "amount": 200.5,
            "debtor": "John Smith"
        },
        {
            "amount": -150.05,
            "debtor": "John Smith"
        }
    ]
}

Metadata

Release files for kaiba 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kaiba 3.0.1
File Size Uploaded Provenance
kaiba-3.0.1.tar.gz 17.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kaiba 3.0.1
File Interpreter ABI Platform
kaiba-3.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 39.1 kB

Release files / kaiba-3.0.1.tar.gz

Download URL kaiba-3.0.1.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0616ce3562e361abb5d5c33bdf6d39d53388c650760b95b2d143e686df3c0f98
BLAKE2b-256 checksum
How to use checksums
5def6e970276ff2f8f2844b0e38d03efe153b825d086996cda1e2c06f6f68f1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.6 Darwin/22.4.0

Release files / kaiba-3.0.1-py3-none-any.whl

Download URL kaiba-3.0.1-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
616f74fa5482259351d45e333e4075960d19dd3b56882d934a1e67bd543704fb
BLAKE2b-256 checksum
How to use checksums
31748d35851d60e61bfeeba6b75b87f44c6460da786cca962a857f1c148eda9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.6 Darwin/22.4.0

Security for kaiba 3.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page