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",
    requests_timeout=1.5,  # This is optional (default: 3 seconds, None means no timeout)
)

# 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.

Metadata

Release files for menshen-client 0.2.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.2.0
File Size Uploaded
menshen_client-0.2.0.tar.gz 6.3 kB Details

Built distribution (wheel)

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

Total release size: 13.5 kB

Release files / menshen_client-0.2.0.tar.gz

Download URL menshen_client-0.2.0.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
548c4224c38b2c844a76325b5a4b65da520ea9eba23aafb004da0f430a7e4fcf
BLAKE2b-256 checksum
How to use checksums
57a25862b0a39d5f96301e1daff146445f591b1980412c20417162f5cfd6aa34
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 Oct 13, 2026.

Transparency log

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

Download URL menshen_client-0.2.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
415eaba30184452bc393b528c6088ed6e37cbd00ce60716aef9e2d9bd0697221
BLAKE2b-256 checksum
How to use checksums
534d932efd81c340d12d07b1c33633c6e7a4a2d0c9086ac0da7ffe9a1ce17068
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 Oct 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.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