Skip to main content

Make authenticated API calls using OAuth2 in Python applications

Project description

Swift OAuth2 Client

PyPI version

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, content_type = client.call_api("GET", "/users")
    print(f"Status: {status}, Content Type: {content_type}, 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, content_type = await client.call_api("GET", "/users")
        print(f"Status: {status}, Content Type: {content_type}, Response: {response}")
    
asyncio.run(main())

For more comprehensive examples, check out the examples/oauth2_client_example_async.py and examples/oauth2_client_example.pyfiles in the repository.

Documentation

For detailed documentation, including API reference and usage guides, visit our documentation site.

Development

To set up the development environment:

  1. Ensure you have Poetry installed
  2. Clone the repository
  3. Run poetry install to install dependencies
  4. Run tests with poetry run pytest

Docs

  1. Build documentation with poetry run mkdocs build
  2. Serve the documentation with poetry run mkdocs serve.
  3. 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

swift_oauth2_client-0.6.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

swift_oauth2_client-0.6.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file swift_oauth2_client-0.6.0.tar.gz.

File metadata

  • Download URL: swift_oauth2_client-0.6.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.0 Darwin/23.6.0

File hashes

Hashes for swift_oauth2_client-0.6.0.tar.gz
Algorithm Hash digest
SHA256 1f28092ce804b89ff262b88edaa504d03520d25e4742bc491124d5ca36a26d7b
MD5 7ab39da786f9074920b9bc7b195f4d4d
BLAKE2b-256 0aa8ca9058b4d18ff28cdd38bf75423bef78b38a8288c6d4c22608da90aa5cec

See more details on using hashes here.

File details

Details for the file swift_oauth2_client-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for swift_oauth2_client-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a37b8c37575751fe9ac581bab71ee909e59e1ea46f674e82b62327c9036289b4
MD5 180a8f3015d15f95fa527c5756632a20
BLAKE2b-256 802ffa663fc99517294c40009ac7d6ecb4c90f870067e1372551dd44a7bc022c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page