![]() |
This article documents something which is not associated with Scratch, the Lifelong Kindergarten Group, the scratch website or the Massachusetts Institute of Technology. |
This tutorial teaches how to access the Scratch API using Python 3.
![]() | Using this to make bots that perform social actions (loving, following, commenting, etc.) violates the Terms of Use and may result in a ban. Please use this appropriately. |
Setup
To access Scratch using Python 3, an IDE for Python 3 is needed. Install the module "scratchclient", made by Raihan142857 to access Scratch. Do this by going into a terminal or Command Prompt and typing pip install scratchclient
. This should download the correct module to access Scratch. Lastly, make sure your device is connected to the internet.
Coding
Once it has been setup, the programming can begin.
![]() | For the functions to display information, such as: session.get_project(PROJECTIDHERE).get_comments()[0].context You may need to use the "print" function to display the information in your console. Like so: print(TEXT) . For example, if you want to get a comment, you would use: print(session.get_project(PROJECTIDHERE).get_comments()[0].context) . |
Follow this script very carefully:
- Import the ScratchSession module with this script:
from scratchclient import ScratchSession
- Login with one's username and password with this script:
session = ScratchSession("username", "password")
- Use the functions below.
Here is a script of the basic things to do (comments have a hashtag (#) before them, they are not actual code. They are notes for clarity):
from scratchclient import ScratchSession
session = ScratchSession("username", "password") #enter account's credentials
Comments
session.get_project(PROJECTIDHERE).post_comment("COMMENTTEXTHERE") #to post comments on projects
session.get_studio(STUDIOIDHERE).post_comment("COMMENTTEXTHERE") #to post comments on studios
session.get_studio(USERNAMEHERE).post_comment("COMMENTTEXTHERE") #to post comments on profiles
session.get_project(PROJECTIDHERE).get_comments()[0].context #To get comments
Cloud Variables
connection = session.create_cloud_connection(PROJECTIDHERE) #To create a cloud connection (must be done first)
connection.set_cloud_variable("VARIABLENAMEHERE", "VALUEHERE") #To set a cloud variable
connection.get_cloud_variable("VARIABLENAMEHERE") #To get a cloud variable
Projects
session.get_project(PROJECTIDHERE).love() #to love a project
session.get_project(PROJECTIDHERE).favorite() #to favorite a project
session.get_project(PROJECTIDHERE).unlove() #to unlove a project
session.get_project(PROJECTIDHERE).unfavorite() #to unfavorite a project
session.get_project(PROJECTIDHERE).description #To get project description
session.get_project(PROJECTIDHERE).instructions #To get a project instructions
session.get_project(PROJECTIDHERE).title #To get the title of a project
session.get_project(PROJECTIDHERE).love_count #To get the amount of loves for a project
session.get_project(PROJECTIDHERE).favorite_count #To get the amount of favorites for a project
session.get_project(PROJECTIDHERE).remix_count #To get the amount of remixes for a project
session.get_project(PROJECTIDHERE).view_count #To get the amount of views for a project
session.get_project(PROJECTIDHERE).comments_allowed #To see if the project allows comments
session.get_project(PROJECTIDHERE).author.username #To see the creator of the project
Studios
![]() |
Please expand this section. You can help by adding more information if you are an editor. More information might be found in a section of the talk page. (August 2021) |
session.get_studio(STUDIOIDHERE).description #To get studio description
Users
session.get_user(USERNAMEHERE).get_message_count() #To get a message count of a user
session.get_user(USERNAMEHERE).follow() #to follow a user
session.get_user(USERNAMEHERE).unfollow() #to unfollow a user
session.get_user(USERNAMEHERE).profile.bio #To get the About Me from a specified user
session.get_user(USERNAMEHERE).get_followers()[0].username #To get the users followers
session.get_user(USERNAMEHERE).joined_timestamp #To get the ISO timestamp of when the user joined
session.get_user(USERNAMEHERE).scratchteam #To get a boolean (true/false) of whether the user is a member of the Scratch Team
Miscllaneous
![]() |
Please expand this section. You can help by adding more information if you are an editor. More information might be found in a section of the talk page. (August 2021) |
session.get_news()[0].title #To get the title of a news in the Scratch News section