Skip to main content

tj-tpauth

tj-tpauth is a Python library for managing user authentication through an API. The library supports both synchronous and asynchronous methods for login and token-based authentication.

Installation

To install the library, use pip:

pip install tj-tpauth

Usage

Synchronous (Sync)

from tj_tpauth import TJTPAuth

# Initialize TJTPAuth object with API URL and optional timeout
tpauth = TJTPAuth(
    host='http://localhost:3000',
    timeout=10
)

# Log in with username and password
login_status = tpauth.login(
    username='username',
    password='password'
)

# Check login status
if not login_status.status:
    exit(0)

# Authenticate with token
auth_status = tpauth.from_token(login_status.data.token)

# Check authentication status
if not auth_status.status:
    exit(0)

# Print authentication data
print(auth_status.data)

Asynchronous (Async)

import asyncio
from tj_tpauth import TJTPAuth

# Initialize TJTPAuth object with API URL and optional timeout
tpauth = TJTPAuth(
    host='http://localhost:3000',
    timeout=10
)


async def main():
    # Log in with username and password
    login_status = await tpauth.aio_login(
        username='username',
        password='password'
    )

    # Check login status
    if not login_status.status:
        exit(0)

    # Authenticate with token
    auth_status = await tpauth.aio_from_token(login_status.data.token)

    # Check authentication status
    if not auth_status.status:
        exit(0)

    # Print authentication data
    print(auth_status.data)


# Run asynchronous function
asyncio.run(main())

Main Classes

  • TPAuthData: Contains user authentication information.
  • TPAuthStatus: Represents the authentication status, including error information.
  • TJTPAuth: Provides synchronous and asynchronous methods for login and token-based authentication.

Error Handling

  • Error.NOTHING: No error.
  • Error.TIMEOUT: Timeout error.
  • Error.UNAUTHORIZED: Unauthorized error.
  • Error.PARSING: Data parsing error.

References

For more information about requests and aiohttp, refer to their official documentation:

License

This library is released under the MIT License.

Contact

If you have any questions or issues, please open an issue on GitHub or email us at duynguyen02.dev@gmail.com.

Metadata

Release files for tj-tpauth 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tj-tpauth 1.1.0
File Size Uploaded
tj_tpauth-1.1.0.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tj-tpauth 1.1.0
File Interpreter ABI Platform
tj_tpauth-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.5 kB

Release files / tj_tpauth-1.1.0.tar.gz

Download URL tj_tpauth-1.1.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
be6623f1b7552968ae4ee4f0c51412eeec8bfe7463fd0f06117027524ce528aa
BLAKE2b-256 checksum
How to use checksums
8a9a1357ffee244d14b59139eaa3e13744c2f8bf68be1a34280e51aaa578bdbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-41-generic

Release files / tj_tpauth-1.1.0-py3-none-any.whl

Download URL tj_tpauth-1.1.0-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60f26b54f5939f47c8e5d605889cd037989e32a6f15e3f85d9caea812660e3be
BLAKE2b-256 checksum
How to use checksums
a5ce3df1d9284fa29edfda0d32d9221c2d4aec16ce780bb608b1a4fadb09a998
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-41-generic

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page