Make authenticated API calls using OAuth2 in Python applications
Project description
Swift OAuth2 Client
Swift OAuth2 Client is a Python SDK that provides a simple and efficient way to interact with OAuth2-protected APIs. It handles token management, API calls, and file downloads with support for asynchronous operations.
Features
- Asynchronous API calls using
httpx
- Automatic token management and renewal
- Support for various request body types and response formats
- File download capabilities
- Easy-to-use interface with type hints
- Comprehensive documentation
Installation
pip install swift-oauth2-client
Quick Start
Here's a basic example of how to use the Swift OAuth2 Client:
from oauth2_client import OAuth2Config, new_api_client
config = OAuth2Config(
token_url="https://api.example.com/oauth/token",
client_id="your_client_id",
client_secret="your_client_secret",
scopes=["read", "write"]
)
with new_api_client(config, "https://api.example.com") as client:
response, status = client.call_api("GET", "/users")
print(f"Status: {status}, Response: {response}")
Asynchronous usage:
import asyncio
from oauth2_client import OAuth2Config, new_api_client_async
async def main():
config = OAuth2Config(
token_url="https://api.example.com/oauth/token",
client_id="your_client_id",
client_secret="your_client_secret",
scopes=["read", "write"]
)
async with new_api_client_async(config, "https://api.example.com") as client:
response, status = await client.call_api("GET", "/users")
print(f"Status: {status}, Response: {response}")
asyncio.run(main())
For more comprehensive examples, check out the examples/oauth2_client_example_async.py
and examples/oauth2_client_example.py
files in the repository.
Documentation
For detailed documentation, including API reference and usage guides, visit our documentation site.
Development
To set up the development environment:
- Ensure you have Poetry installed
- Clone the repository
- Run
poetry install
to install dependencies - Run tests with
poetry run pytest
Docs
- Build documentation with
poetry run mkdocs build
- Serve the documentation with
poetry run mkdocs serve
. - Open a web browser and go to http://127.0.0.1:8000/.
License
This project is licensed under the Apache License, Version 2.0.
Project details
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
File details
Details for the file swift_oauth2_client-0.3.0.tar.gz
.
File metadata
- Download URL: swift_oauth2_client-0.3.0.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.0 Darwin/23.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6591dbf2760c82c7c24eb7335ec830a7191ff52d708e9af1b4176d9f8caf1de2 |
|
MD5 | 8c76d0ce7ca966c3ba522f1d6e71ce38 |
|
BLAKE2b-256 | 17ac7f564d104efabd02879a6a9af55d97899c147e6ecf4e2d02f3fee6a1f035 |
File details
Details for the file swift_oauth2_client-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: swift_oauth2_client-0.3.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.0 Darwin/23.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d816ec0ffba3adbea5d044fcb835a820c7c3faf9c6bb7eab2c5d3ff0931bfbec |
|
MD5 | e57cc030aff84c1b2f87e85548f9cae4 |
|
BLAKE2b-256 | e246525f63e8c3d1247f28761e78ec3134050255e0a47978d79f1dda4bc34de6 |