Intro To Gokart


Within the activated Python environment, use the following command to install gokart.

pip install gokart


A minimal gokart tasks looks something like this:

import gokart

class Example(gokart.TaskOnKart):
    def run(self):
        self.dump('Hello, world!')

task = Example()
output =
print(output) return the result of dump by gokart.TaskOnKart. The example will output the following.

Hello, world!

gokart records all the information needed for Machine Learning. By default, resources will be generated in the same directory as the script.

$ tree resources/
├── __main__
│   └── Example_8441c59b5ce0113396d53509f19371fb.pkl
└── log
    ├── module_versions
    │   └── Example_8441c59b5ce0113396d53509f19371fb.txt
    ├── processing_time
    │   └── Example_8441c59b5ce0113396d53509f19371fb.pkl
    ├── random_seed
    │   └── Example_8441c59b5ce0113396d53509f19371fb.pkl
    ├── task_log
    │   └── Example_8441c59b5ce0113396d53509f19371fb.pkl
    └── task_params
        └── Example_8441c59b5ce0113396d53509f19371fb.pkl

The result of dumping the task will be saved in the __name__ directory.

import pickle

with open('resources/__main__/Example_8441c59b5ce0113396d53509f19371fb.pkl', 'rb') as f:
    print(pickle.load(f))  # Hello, world!

That will be given hash value depending on the parameter of the task. This means that if you change the parameter of the task, the hash value will change, and change output file. This is very useful when changing parameters and experimenting. Please refer to Task Parameters section for task parameters. Also see TaskOnKart section for information on how to return this output destination.

In addition, the following files are automatically saved as log.

  • module_versions: The versions of all modules that were imported when the script was executed. For reproducibility.
  • processing_time: The execution time of the task.
  • random_seed: This is random seed of python and numpy. For reproducibility in Machine Learning. Please refer to Task Settings section.
  • task_log: This is the output of the task logger.
  • task_params: This is task’s parameters. Please refer to Task Parameters section.

How to running task

Gokart has run and build methods for running task. Each has a different purpose.

  • uses arguments on the shell. return retcode.
  • uses inline code on jupyter notebook, IPython, and more. return task output.


It is not recommended to use and together in the same script. Because will clear the contents of luigi.register. It’s the only way to handle duplicate tasks.

The run() is running on shell.

import gokart
import luigi

class SampleTask(gokart.TaskOnKart):
    param = luigi.Parameter()

    def run(self):
python SampleTask --local-scheduler --param=hello

If you were to write it in Python, it would be the same as the following behavior.['SampleTask', '--local-scheduler', '--param=hello'])

The build() is inline code.

import gokart
import luigi

class SampleTask(gokart.TaskOnKart):
    param = luigi.Parameter()

    def run(self):
        self.dump(self.param)'hello'), return_value=False)