Python SDK
The official Python library for rNet OAuth authentication and authenticated AI calls.
PyPI: rnet-oauth
Installation
1. Initialize the Clients
from rnet_oauth import RNetAuth, RNetAi
auth = RNetAuth(
client_id='your-client-id',
client_secret='your-client-secret',
redirect_uri='your-redirect-uri'
)
ai = RNetAi()2. Generate Authorization URL (OAuth2 PKCE)
pkce = auth.generate_pkce()
auth_url = auth.get_authorization_url(pkce['challenge'], state='optional-state')
3. Exchange Code for Tokens
tokens = auth.exchange_code_for_token(code, pkce['verifier'])
access_token = tokens['access_token']
refresh_token = tokens['refresh_token']
4. Refresh Tokens
refreshed_tokens = auth.refresh_access_token(refresh_token)
new_access_token = refreshed_tokens['access_token']
5. Get User Info
user_info = auth.get_user_info(access_token)
print(user_info['email'])
print(user_info['name'])
The UserInfo response comes from RNet's /userinfo endpoint and may include: sub, email, email_verified, name, preferred_username, user_id, role, and status.
6. Chat with AI
response = ai.chat({
"contents": [
{"role": "user", "parts": [{"text": "Hello!"}]}
]
}, access_token, "gemini-2.5-flash-lite")7. Streaming AI Response (Untested)
for chunk in ai.chat_stream(payload, access_token, "gemini-2.5-flash-lite"):
print(chunk)8. File Upload (Untested)
with open("document.pdf", "rb") as f:
file_buffer = f.read()
# Upload to Gemini
gemini_upload = ai.gemini_file_upload(access_token, "gemini-2.5-flash-lite", file_buffer, "application/pdf", "document.pdf")
print(gemini_upload['fileReference']) # Use this in chat payload
# Upload to OpenAI
openai_upload = ai.openai_file_upload(access_token, "gpt-4o", file_buffer, "application/pdf", "document.pdf")9. File Deletion (Untested)
# Gemini files auto-delete after 48 hours, so there is no delete method.
# Delete an OpenAI file:
ai.openai_file_delete(access_token, "gpt-4o", openai_upload['fileReference'])
10. AI Chat with File & Tools (Untested)
payload = {
"contents": [
{
"role": "user",
"parts": [
{"text": "Based on this document, what is my name? Also search the web for the current weather in London."},
{"fileData": {"fileUri": gemini_upload['fileReference'], "mimeType": gemini_upload['mimeType']}}
]
}
],
"tools": [
{"googleSearch": {}} # Enable Google Search tool
]
}
response = ai.chat(payload, access_token, "gemini-2.5-flash-lite")
print(response)Repository
View the Python SDK on GitHub.