import pywikibot
site = pywikibot.Site('en', 'wikipedia')  # The site we want to run our bot on
page = pywikibot.Page(site, 'Wikipedia:Sandbox')
page.text
'{{Please leave this line alone (sandbox heading)}}<!--\n*               Welcome to the sandbox!              *\n*            Please leave this part alone            *\n*           The page is cleared regularly            *\n*     Feel free to try your editing skills below     *\n■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■-->Fgc'
import mwapi
session = mwapi.Session('https://en.wikipedia.org')

print(session.get(action='query', meta='userinfo'))
Sending requests with default User-Agent.  Set 'user_agent' on mwapi.Session to quiet this message.
{'batchcomplete': '', 'query': {'userinfo': {'id': 0, 'name': '10.68.23.110', 'anon': ''}}}