C3 AI Documentation Home

Understanding and Using the C3 AI Type System

The C3 AI Type System serves as a unified programming interface that seamlessly integrates various components of the C3 AI Platform, including infrastructure and services. C3 AI Types define metadata and form the core of the platform's architecture. The Type System emphasizes defining interfaces and designing all elements as Types before implementation. These Types can represent a wide array of elements, such as data objects, application logic, machine learning classifiers, databases, and queues.

Types overview

Some Types are pre-defined and integrated into the platform, ensuring consistency across various underlying technologies. These platform Types provide advanced functionality and high-level services on top of basic technologies. Other Types are created by developers using the platform. For an overview of key Types and the C3 AI Type System, see Platform Types in the C3 AI Type System.

Declare a Type

Types are expressed in a Domain-Specific Language (DSL) with bindings for JavaScript and Python. Each Type is maintained in a .c3typ file, typically located under src/ within a package.

A Type is a collection of fields, methods, mixins, and annotations that operate on data.

To declare a basic Type create a file Automobile.c3typ:

Type
type Automobile

This example defines an Automobile Type with no fields or methods. Starting with such a basic Type allows you to focus on how to create a Type and perform operations on it, such as viewing the Type's metadata and browsing the Type System documentation. This foundational understanding is crucial before adding more complexity with fields and methods.

Most Types inherit (or mixin) the default Type Obj. Obj supports instance creation and management. Each Type contains metadata that describes its structure and behavior.

You can find a complete list of the functions for a Type by using the c3ShowType command in the console.

For example, the following command returns the documentation for the Type Type.

JavaScript
c3ShowType(Type);

A Type's metadata is accessible through the TypeMeta Type. You can read more about using TypeMeta under the Advanced Topics section, Type Introspection.

Instantiating objects

Instantiating Types is a fundamental operation in the Type System.

Note: Depending on your needs, you can create in-memory or persistent instances of a Type. Understanding the difference between these methods is crucial for efficient application development. You can find out more information about creating persistent Types in the topic persisting data.

In-Memory instantiation

You can instantiate an in-memory object using make. You can use make to instantiate an object of a Type without persisting it to the database.

JavaScript
// Create an instance of Automobile in memory
var automobile = Automobile.make();

In Python, C3 AI Types are accessible through the special c3 global variable, which is available in hosted JupyterLab sessions as well as in server-side methods and pipelines. To save memory and reduce startup time, Types are loaded on demand.

In [1]:

Python
# The C3 AI scope should already be defined for you
c3

You can access Types through the scope. For example, you can access the Automobile Type as follows:

In [2]:

Python
c3.Automobile

Automobile is like any other Python class. For example, you can use dir() to list its fields and methods:

In [3]:

Python
dir(c3.Automobile)[:10] # show just the first 10 attributes

You can create an instance of an object from its Type using the standard Python class constructor notation. The only limitation is that any parameters must be passed as keyword arguments. In other words, positional arguments are not allowed.

For example, create an instance of the Automobile Type, as follows in JavaScript or Python:

JavaScript
var auto = Automobile.make({
    model: "Porsche",
    color: "white",
    year: 2024
});

In [4]:

Python
c3.Automobile(model="Porsche", color="white", year="2024")

In the static console, you can use the standard c3showtype() function to retrieve the documentation for a given C3 AI Type:

JavaScript
c3ShowType(Type);

In a Jupyter notebook, you can use the standard help() function to retrieve the documentation for a given C3 AI Type:

In [5]:

Python
help(c3.Type)

Next steps: Creating Types with fields and methods

Now that you have an understanding of creating basic Types and working with their instances, it's time to move on to the next topic and learn how add fields to Types.

Was this page helpful?