Sololearn API for python.
The script is outdated and propably requires javascript. Will be converted into selenium at some point
Requires requests, BeautifulSoup 4 and json libraries
Before you can use this API you must login with your sololearn account
import sl
login = sl.Login("email", "password")
Login instance contains following properties
Returns a list of Post objects
Parameters- order Trending, MostRecent, Unanswered, MyQuestions, MyAnswers. Trending is the default value
- page Each page returns 20 posts
- query Keyword used to search posts
import sl
login = sl.Login("email", "password")
posts = login.getPosts(order="myquestions", page=2)
More information in Post object section
Returns a list of Code objects
Parameters- order Trending, MostRecent, MostPopular, MyCodes
- page Each page has 20 codes
- query Keyword used to search codes
- language Codes by specific language. Must be used with the alias of the language. Listed below. Searches all languages by default
web, cpp, c, cs, java, py, php, rb, kt, swift
import sl
login = sl.Login("email", "password")
codes = login.getCodes(query="website", language="web")
More information in Code object section
Returns User object for given user id
import sl
login = sl.Login("email", "password")
user = login.getUser(7745624)
print(user.name)
print(user.level + " " + user.xp)
More information in User object section
Creates and saves a new code for your user
Parameters- name
- code source code
- cssCode only used with web language to specify source code for css
- jsCode only used with web language to specify source code for javascript
- language Required. Must be used with the alias of the language. Listed below
- public boolean
web, cpp, c, cs, java, py, php, rb, kt, swift
import sl
login = sl.Login("email", "password")
login.newCode(language="py", name="Python code", code="print('hello world')", public=True)
login.newCode(language="web", name="Web code", code="html code", cssCode="css code", jsCode="javascript code", public=False)
Post object contains information for a single post
It contains following properties
- id
- title
- link
- votes
- currentVote
- text
- answers
- tags
- date
- author (User object)
- getAnswers
- sendAnswer
- edit
- delete
- vote
- json
Returns a list of Answer objects
Parameters- index starting index. Returns 20 answers starting from the index
- order get answers by votes or date
import sl
login = sl.Login("email", "password")
posts = login.getPosts()
answers = posts[0].getAnswers(order="date", index=100)
More information in Answer object section
(Post object)
Parameters- title
- text
- tags (list)
Only possible for your own posts/questions
If parameter is not used it will keep its original content
import sl
login = sl.Login("email, "password")
posts = login.getPosts(order="myquestions")
posts[0].edit(title="answer title", text="answer body", tags=["tag1", "tag2"])
Is used to store information for user
This method is used to get more specific information about the user
Returns Profile object
This method takes no parameters
Retrieves more specific information for user
Only callable from User object
It contains following properties
- id
- name
- avatar
- level
- xp
- courses (dictionary)
- codes (list of Code objects)
- certificates (dictionary)
- achievements (dictionary)
Parent object properties are synchronized along with the Profile object properties
Answer object contains information for a single answer
Answer objects are returned from getAnswers method in Post object
It contains following properties
(Answer object)
Takes a single string as parameter
Only possible for your own answers
import sl
login = sl.Login("email", "password")
posts = login.getPosts()
answers = posts[0].getAnswers(order="date", index=100)
answers[0].edit("edited")
Post object contains information for a single post
It contains following properties
- id
- publicId
- language
- link
- name
- votes
- currentVote
- date
- author (User object)
- source
- edit
- execute
- vote
- delete
- json
Returns dictionary including source code for Code object
Values- code the actual source code. Contains html source code when using web language
- cssCode Contains source code for css language. only used with web language. Otherwise empty
- jsCode Contains source code for javascript language. only used with web language. Otherwise empty
import sl
login = sl.Login("email", "password")
codes = login.getCodes()
source = codes[0].source()
print(source["code"])
(Code object)
Parameters- name
- code source code
- cssCode only used when editing code with web language
- jsCode only used when editing code with web language
- language Keeps the original language by default. Must be used with the alias of the language. Listed below
- public
Only possible for your own codes
Language aliasesweb, cpp, c, cs, java, py, php, rb, kt, swift
import sl
login = sl.Login("email", "password")
codes = login.getCodes()
codes[0].edit(name="Edited", code="print('edited')", public=False)
This method is property of Post, Answer and Code objects
Deletes the object
This method takes no parameters
import sl
login = sl.Login("email", "password")
posts = login.getPosts(order="myquestions")
codes = login.getCodes(order="mycodes")
answers = posts[0].getAnswers()
posts[0].delete()
codes[0].delete()
if(answers[0].author.id == login.id):
answers[0].delete()
This method is property of Post, Answer and Code objects
Sends a vote to the parent object
parameters- amount values 1, 0 and -1
value 1 upvotes
value 0 removes upvote or downvote
value -1 downvotes
import sl
login = sl.Login("email", "password")
posts = login.getPosts()
codes = login.getCodes()
answers = posts[0].getAnswers()
posts[0].vote(1)
codes[0].vote(0)
answers[0].vote(-1)
import sl
login = sl.Login("email", "password")
questions = login.getPosts(order="myquestions")
for question in questions:
question.delete()
import sl
login = sl.Login("email", "password")
codes = login.getCodes()
for code in codes:
print(code.author.id)
print(code.author.name)
print(code.author.avatar)
import sl
login = sl.Login("email", "password")
login.newCode(language="py", name="new code", code="print('Hello World')")
codes = login.profile().codes
print(codes[0].execute())