Skip to main content

Python client for the Eternal-Twin API

Project description

PyPI Version Documentation Status Python 3.11+ License AGPL-3.0-or-later Tests codecov CodeFactor

EternalTwin Python Client

eternaltwinpy is an unofficial Python client for the EternalTwin API. It let you authenticate and retrieve users information.

You can view the full documentation at https://eternaltwinpy.readthedocs.io/en/latest/.

Features

  • Provides a high-level API to make authorization and user information retrieval easier.
  • Provides a low-level API to interact directly with the EternalTwin API.
  • Support both synchronous and asynchronous HTTP requests.

Requirements

eternaltwinpy supports the officially supported versions of Python (mainstream & LTS).

Installation

Install via pip:

pip install eternaltwin

or poetry:

poetry add eternaltwin

Quickstart

Configure the connection

See Configuration for more details.

from eternaltwin.connections import configure
from eternaltwin.keys import HS256Key

ETERNALTWIN_CONFIG = {
    "default": {
        'url': 'https://eternaltwin.org/api/v1/',
        'client_id': "myclient",
        'client_secret': 'mysecret',
        'redirect_uri': 'https://myapp.com/callback',
        'state_key': HS256Key("mykey"),
        'allow_redirects': True,
    },
    "test": {
        'url': 'http://localhost:50321/api/v1"',
        'client_id': "myclient",
        'client_secret': 'mysecret',
        'redirect_uri': 'https://localhost:8080/callback',
        'state_key': HS256Key("mykey"),
        'timeout': 1,
        'verify_ssl': False,
    }
}
configure(**ETERNALTWIN_CONFIG)

Oauth2 Authorization

See OAuth2 Authorization for more details.

from eternaltwin.users import User
from eternaltwin.exceptions import InvalidStateError

# Generate a state and an authorization URL.
# The state can be used to find which auth request the response corresponds to
# if the callback is handled by a different thread, worker, or process than the
# one that created the auth request.
state, url = User.start_authorization()

# Redirect the user to the url, once authenticated EternalTwin will redirect
# back to your `redirect_uri` with additional query parameters `code` and `state`.
authorization_code =  # Extract the `code`
response_state =  # Extract the `state`

# Ensure the state is as expected to prevent CSRF attacks. 
try:
    user = User.from_authorization_code(authorization_code, response_state, state)
except InvalidStateError:
    ...

assert user.is_authenticated is True
print(user.identifier)
# "<user_id>"
print(user.username)
# "<username>"

Retrieving User Information

See Working with Users for more details.

from eternaltwin.users import User

# Get a specific user by ID
user = User.get("<user_id>")
print(user.identifier)
# "<user_id>"
print(user.username)
# "Bob"

# Search for users by username
users = User.search("Jhon")

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

eternaltwin-1.0.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

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

eternaltwin-1.0.0-py3-none-any.whl (29.5 kB view details)

Uploaded Python 3

File details

Details for the file eternaltwin-1.0.0.tar.gz.

File metadata

  • Download URL: eternaltwin-1.0.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for eternaltwin-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e54c89f9006f9292e0db6983e4a8fa468f22d672f03940fb9656724fb4eb5d19
MD5 95a7b8e938d500fa2a0080a1ca207759
BLAKE2b-256 9d2db17f7d301b442f5bcee9178d5a2d965fa4bc890bb5e2ac02160ae9263f00

See more details on using hashes here.

Provenance

The following attestation bundles were made for eternaltwin-1.0.0.tar.gz:

Publisher: test_and_publish.yml on qcoumes/eternaltwinpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file eternaltwin-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: eternaltwin-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 29.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for eternaltwin-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93d44daf07272f80e4583dba27f3e34045293d214f7558604037a5f34e258f0f
MD5 1904ff940b95954f2feadb27175cb9f8
BLAKE2b-256 e3c9c9b4b91cd8c9a3af16857d1bd758e0b8cdd69f4c3baff3b98a41772dad24

See more details on using hashes here.

Provenance

The following attestation bundles were made for eternaltwin-1.0.0-py3-none-any.whl:

Publisher: test_and_publish.yml on qcoumes/eternaltwinpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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