Skip to main content

Menshen API client

menshen_client is an API client distributed as a Python's library to integrate Menshen OAuth2 Token Exchange server in your autorization flow. It has been designed to add few extra-dependencies to your project.

Installation

The API client is available from PyPI and can be added to your project using:

uv add menshen_client
# or
pip install menshen_client

Usage

Configure the client

You can create your client configuration using the following snippet:

from menshen_client import Configuration, TokenExchangeClient

# Configure the client
config = Configuration(
    client_id="acme",
    client_secret="super-secret",
    server_root_url="https://menshen.example.org",
)

# Create the client instance
client = TokenExchangeClient(config=config)

In this example, the client identifier and secret are those provided by your Menshen instance administrator that should have registered a service provider for your service. The server_root_url is the root URL of your Menshen server.

Token exchange request

To generate an exchange token given a subject token and a related token type use:

from menshen_client import (
    TokenExchangeRequest,
    TokenExchangeResponse,
    TokenType,
)

# Create the token exchange request
exchange_request = TokenExchangeRequest(
    subject_token="exampletoken",
    subject_token_type=TokenType.ACCESS_TOKEN,
    audience="https://target.example.org",
    scope="target:write",
)

# Get the exchanged token response
exchange_response: TokenExchangeResponse = client.exchange(exchange_request)

For a full list of available fields in the token exchange request, please check the TokenExchangeRequest dataclass in the project's repository (and the RFC 8693).

The token exchange response contains the exchanged token that can be used to query the target resource server:

import requests

resources = requests.get(
    "https://target.example.org/external_api/v1.0/resource/",
    headers={
        "Authorization": f"Bearer {exchange_response.access_token}",
        "Content-Type": "application/json",
    },
)

For a full list of available fields in the token exchange response, please check the TokenExchangeResponse dataclass in the project's repository (and the RFC 8693).

Exchanged token instrospection

If you are the target resource server, you may want to introspect exchanged tokens via your autorization server instance using:

from menshen_client import (
    IntrospectionRequest,
    IntrospectionResponse,
    TokenType,
)

# Create the token instrospection request
introspection_request = IntrospectionRequest(
    token="exampletoken",
    token_type_hint=TokenType.ACCESS_TOKEN,
)

# Get the token introspection response
introspection_response: IntrospectionResponse = client.introspect(introspection_request)

# Check if the token is still valid to access the resource and get user information
assert introspection_response.active
assert introspection_response.sub == "1234567890"
assert introspection_response.email == "jane.doe@example.org"

For a full list of available fields in the token instrospection response, please check the IntrospectionResponse dataclass in the project's repository (and the RFC 7662).

Exchanged token revocation

If for any reason, you want to revoke an exchaged token, you can query your Menshen instance dedicated endpoint:

from menshen_client import (
    RevocationRequest,
    TokenType,
)

# Create the token revocation request
revocation_request = RevocationRequest(
    token="exampletoken",
    token_type_hint=TokenType.ACCESS_TOKEN,
)

# Token revocation response is empty
client.revoke(revocation_request)

License

This work is released under the MIT License (see LICENSE).

While this project is a public-driven initiative, our license choice is an invitation for private sector actors to use, sell and contribute to it.

Release files for menshen-client 0.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 menshen-client 0.1.0
File Size Uploaded
menshen_client-0.1.0.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for menshen-client 0.1.0
File Interpreter ABI Platform
menshen_client-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.3 kB

Release files / menshen_client-0.1.0.tar.gz

Download URL menshen_client-0.1.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
21fe48788e860c7f2e103787ce0827981e9059146cf7bdb9ac1a8778acb9ff77
BLAKE2b-256 checksum
How to use checksums
53d5c2be400c190efe26b70e5c60dd9d9ab279ece3b51de457abc184a238c727
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / menshen_client-0.1.0-py3-none-any.whl

Download URL menshen_client-0.1.0-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0dfb351812bb93620a4796e0f0ce1a40e8ec859dc8de2a1f50ae7f306d4d29a
BLAKE2b-256 checksum
How to use checksums
d6bf11d15da4852b8344eb9f30861bd15a8f1d931ff4232d9b7de18fce09fd3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

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