RNet OAuth Python client library
Project description
RNet OAuth Python Library
A Python backend library for integrating RNet OAuth and AI Provider services. This library allows users to authenticate via RNet and pay for AI model token costs directly using their RNet account.
Features
- OAuth2 PKCE Support: Secure authorization code flow with automatic code verifier and challenge generation.
- Token Management: Exchange authorization codes for tokens and refresh expired tokens.
- UserInfo Endpoint: Fetch the authenticated user's RNet profile with an access token.
- AI Integration: Easy methods to chat with AI models using standard or streaming responses.
Installation
pip install rnet-oauth
Quick Start
1. Initialize the Clients
from rnet_oauth import RNetAuth, RNetAi
auth = RNetAuth(
client_id='client-id',
client_secret='client-secret',
redirect_uri='redirect-uri'
)
ai = RNetAi()
2. Generate Authorization URL (OAuth2 PKCE)
# 1. Generate PKCE
pkce = auth.generate_pkce()
verifier = pkce['verifier']
challenge = pkce['challenge']
# 2. Get Authorization URL
# challenge: PKCE code challenge (optional)
# state: An optional string to maintain state between the request and callback (recommended for security)
auth_url = auth.get_authorization_url(challenge, state='optional-state')
3. Exchange Code for Tokens
# 3. Exchange code for tokens
tokens = auth.exchange_code_for_token(code, verifier)
access_token = tokens['access_token']
4. 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.
5. Chat with AI
response = ai.chat({
"contents": [
{
"role": "user",
"parts": [{"text": "Hello!"}]
}
]
}, access_token, "gemini-2.5-flash-lite")
6. Streaming AI Response (Untested)
for chunk in ai.chat_stream({
"contents": [
{
"role": "user",
"parts": [{"text": "Hello!"}]
}
]
}, access_token, "gemini-2.5-flash-lite"):
print(chunk)
7. 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")
8. 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'])
9. 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)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rnet_oauth-1.0.1.tar.gz.
File metadata
- Download URL: rnet_oauth-1.0.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c69753554a2f792fa07c81d3dc45fd20065b791de786fbe5bc83711929e4cad
|
|
| MD5 |
da0bab1aa080a38f91d3850c2e238e5b
|
|
| BLAKE2b-256 |
ca9f0d4b54bf9055cbabc47a33ad57a792b42572dc0c43feb211d5e2ae5ae61c
|
File details
Details for the file rnet_oauth-1.0.1-py3-none-any.whl.
File metadata
- Download URL: rnet_oauth-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a21cf854b73b84d915e301041370f738e9114cb950f27699bb4d316a4e95eb7
|
|
| MD5 |
a592ca4a1eeb31fc4fbae74ab8b5c649
|
|
| BLAKE2b-256 |
4ad08bcc8486bb6ac4e3b5285a6c60286a7d43df77869da780bed9c80e5de3a8
|