Block AI LabCoding Playground

Python Guide ๐Ÿ

Every block is a real Python function. Use them in Python mode exactly as written here.

Getting started

Start a Python project, or open a blocks project and choose Edit as Python to turn your blocks into code. Programs begin with from ailab import *, which gives you every function below. Python waits for the AI for you, so you never need await.

from ailab import *

set_personality("a friendly robot who loves space")
name = input("What is your name?")
reply = chat(f"Say hello to {name} and share a space fact")
say(reply)
speak(reply, voice="robot")

Chat AI

chat("message")
Ask the AI brain. It remembers the conversation and returns its reply.
set_personality("a pirate")
Choose who the AI pretends to be.
forget_chat()
Start a fresh conversation.
ask("question")
Ask the person a question and wait for the typed answer. input() works too.
ai_sort("text", "happy, sad")
The AI picks the best matching group.
write_story("topic")
The AI writes a short story.

Create

draw("a cat astronaut")
The AI draws a cartoon of anything you describe and shows it on the stage.
paint("a cat astronaut", style="cartoon")
Generate a painted picture with an AI image model.

Cartoon stories

set_background("a sunny beach")
The AI draws the place where your story happens.
add_character("Spark", "a friendly dragon", "left")
The AI draws a character and puts it at left, middle or right.
move_character("Spark", "right")
Move a character. You can also use a number from 10 to 90.
character_says("Spark", "Hello!")
A speech bubble above the character. Empty text hides it.
remove_character("Spark")
Take a character off the stage.
add_comic_panel("Once upon a time...")
Snap the scene into your comic strip. It appears in the Comic tab.
clear_comic()
Start a new comic.

Vision

start_camera() / stop_camera()
Turn the webcam on or off.
take_photo()
Freeze the camera into a photo.
recognise("camera")
Name the main thing seen. Also accepts "photo" or an asset name.
confidence()
How sure the last guess was, 0 to 100.
spot_objects()
List of objects found in live video. Draws boxes on the stage.
count_objects("person")
How many of something the camera sees.
colour_in_middle()
Name of the colour in the middle of the camera.
colour_amount("red")
Amount of red, green, blue or brightness, 0 to 100.
describe_photo("camera")
The AI looks at the camera, a photo or a picture and describes it.
ask_about_photo("what colour is it?", "camera")
Ask the AI a question about what it can see.

Teach your own model

teach_image("label")
Add the current camera picture as an example.
guess_image()
Guess a label using the examples taught.
teach_text("I love it", "happy")
Add a text example.
guess_text("text")
Guess the label of new text.
feeling("text")
positive, negative or neutral.
examples_taught()
How many examples the models have.
forget_teaching()
Clear both models. What you teach is saved with your project until you do this.

Stage and sound

say("hi", seconds=2)
Speech bubble on the stage.
set_face("happy")
happy, sad, thinking, surprised, sleepy, excited.
show_picture("name.png")
Show an uploaded asset or a web link.
clear_stage()
Clear pictures, boxes and the bubble.
speak("hello", voice="robot")
Say it out loud: normal, robot, squeaky or deep.
listen()
Use the microphone and return the words heard.
wait(1)
Pause for some seconds. time.sleep() works too.
run_together(f, g)
Run several of your functions at the same time.
stop_program()
Stop the whole program, like pressing Stop.

Events and variables

@when_key_pressed("space")
Put above a def: the function runs every time the key is pressed. Keys: space, arrows, enter, letters, numbers or any.
@when_stage_clicked
Put above a def: the function runs every time the stage is clicked.
show_variable("score")
Show a variable under the stage. It updates by itself.
hide_variable("score")
Stop showing a variable.
my_list.append(item)
Add an item to the end of a list.
item in my_list
True if the item is in the list.

Real Python

Python 3.13
Your code runs in real CPython 3.13 in the browser, so everything from Python 3.12 and 3.13 works.
import math, random, json, ...
The standard library works. numpy, pandas and matplotlib load automatically when you import them.
plt.show()
matplotlib charts appear on the stage.
help(chat)
Every AI function has built-in help. US spellings like recognize() and color_in_middle() work too.
Functions and classes
Your functions and methods can use AI functions. Python waits for the AI for you, so you never need await.