Skip to main content

Python SDK for TargetAI API

Project description

TargetAI Python SDK

A Python SDK for interacting with the TargetAI API.

Installation

pip install targetai

Quick Start

Here's a complete example showing how to use the SDK:

import asyncio
from targetai import Auth

async def main():
    # Initialize authentication with custom base URL (default is http://localhost:8000)
    auth = Auth(
        email="your_email@example.com",
        password="your_password",
        base_url="http://localhost:8000"  # Change this to your API URL
    )

    try:
        # Login and get tokens
        response = await auth.login()
        print(f"Access token: {response.access_token}")
        print(f"Refresh token: {response.refresh_token}")

        # Check authentication status
        status = await auth.get_status()
        print(f"Is authenticated: {status['isAuthenticated']}")
        print(f"User info: {status['user']}")

        # Refresh tokens when needed
        new_tokens = await auth.refresh()
        
        # Logout when done
        await auth.logout()
    
    finally:
        # Always close the session
        await auth.close()

# Run the async example
if __name__ == "__main__":
    asyncio.run(main())

You can also use the context manager pattern:

async def main():
    async with Auth(
        email="your_email@example.com",
        password="your_password",
        base_url="http://localhost:8000"
    ) as auth:
        response = await auth.login()
        print(f"Successfully logged in!")

Features

  • Simple authentication with email and password
  • Token refresh support
  • Session management with logout
  • Authentication status checking
  • Async support for all operations
  • Type hints for better IDE support
  • Configurable base URL for API endpoints

Requirements

  • Python 3.7+
  • aiohttp
  • pydantic

License

MIT

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

targetai-0.0.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

targetai-0.0.1-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file targetai-0.0.1.tar.gz.

File metadata

  • Download URL: targetai-0.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for targetai-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e57e6098eb2e97de6828aa49db3e11157699924a45018be2bc60fa48911cc52f
MD5 bb4089f76153fbf038e3cefc585ef802
BLAKE2b-256 52c79d0e17dc3376c4cb0b8120515d492545eef7d83fdb0943b93c52d1d186a4

See more details on using hashes here.

File details

Details for the file targetai-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: targetai-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for targetai-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3468a4a058c0818392baf716cddb4d3074b96f0b82328bd2ed440d8772c13f7c
MD5 2a29bb4e8a504137fa7208e7c186873a
BLAKE2b-256 206a34f8a02480521dd272937a79efbe5080c0842a34073fddf804fdb4f07280

See more details on using hashes here.

Supported by

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