Install & Compatibility
Where this runs
tested against v0.7.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.392s · 22.6MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.1s · import 0.384s · 23MB
20MB installed
● package 20MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
OAuth1Service
✓ from rauth import OAuth1Service
OAuth2Service
✓ from rauth import OAuth2Service
OflyService
✓ from rauth import OflyService
This quickstart demonstrates a basic OAuth 2.0 authorization code flow using Rauth. It simulates a web application by prompting the user to manually visit an authorization URL and then input the received authorization code to obtain an access token and make an authenticated API call. Remember to replace placeholder URLs and credentials with actual values for your OAuth provider.
import os
import webbrowser
from rauth import OAuth2Service
# --- Configuration (Replace with your actual app details and environment variables) ---
CLIENT_ID = os.environ.get('RAUTH_CLIENT_ID', 'your_client_id')
CLIENT_SECRET = os.environ.get('RAUTH_CLIENT_SECRET', 'your_client_secret')
REDIRECT_URI = 'http://localhost:8000/callback'
# Example for a hypothetical OAuth 2.0 provider
service = OAuth2Service(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
name='example_provider',
authorize_url='https://example.com/oauth/authorize',
access_token_url='https://example.com/oauth/token',
base_url='https://example.com/api/'
)
print('--- Starting OAuth 2.0 Flow ---')
# Step 1: Get the authorization URL and redirect the user
params = {
'redirect_uri': REDIRECT_URI,
'response_type': 'code',
'scope': 'read_profile'
}
authorize_url = service.get_authorize_url(**params)
print(f"Please visit this URL in your browser:\n{authorize_url}")
webbrowser.open(authorize_url)
# In a real web application, this 'code' would come from the redirect_uri callback
# For this example, we simulate getting the code from user input after manual authorization.
authorization_code = input('Enter the authorization code from the redirect URL: ')
# Step 2: Exchange the authorization code for an access token
data = {
'code': authorization_code,
'grant_type': 'authorization_code',
'redirect_uri': REDIRECT_URI
}
session = service.get_auth_session(data=data, decoder=lambda x: x.json())
# Step 3: Make an authenticated request
try:
response = session.get('user/profile') # Example API endpoint
response.raise_for_status() # Raise an exception for HTTP errors
user_profile = response.json()
print(f"Successfully fetched user profile: {user_profile}")
except Exception as e:
print(f"Error during API request: {e}")
if hasattr(e, 'response') and e.response is not None:
print(f"Response content: {e.response.text}")
print('--- OAuth 2.0 Flow Complete ---')
Upgrade
Version history
0.7.3latest on PyPI · released Jan 22, 2017
Audit
Dependencies
requestsrequiredRauth is built on top of the Requests library for HTTP communication.