Skip to main content

Matrix server resolver library for Python

Project description

ResolveMatrix

ResolveMatrix is a Python library providing the utilities required to resolve both client and server to server API endpoints. It fully conforms to the Matrix specification outlined in the client-to-server specification and server-to-server specification.

Installing

For now, only available via Git:

pip install git+https://codeberg.org/timedout/resolvematrix.git

Usage

Command line

You can use the command mxresolve to resolve a server name from the command line:

$ mxresolve example.com
https://matrix.example.com

Client to Server

You can resolve a server name as follows:

import resolvematrix

resolver = resolvematrix.ClientResolver()
result = resolver.resolve("example.com")
print(result)  # "https://matrix.example.com"

# You can also use the server_from_user_id helper utility to extract the server name from a user ID:
result = resolver.resolve(resolvematrix.server_from_user_id("@alice:example.com"))
print(result)  # "https://matrix.example.com"

# And even manually pass a server URL!
result = resolver.resolve("https://matrix.example.com")
print(result)  # "https://matrix.example.com"

Server to Server

You can resolve a server name as follows:

import resolvematrix

resolver = resolvematrix.ServerResolver()
result = resolver.resolve("matrix.org")
print(repr(result))  # "ServerDestination(hostname='matrix-federation.matrix.org:443', host_header='matrix-federation.matrix.org:443', sni='matrix-federation.matrix.org')"

# You then need to do a little bit of wrangling to get an actual connection.
import httpx

response = resolver.client.get(
    f"{result.base_url}/_matrix/federation/v1/version",
    headers={"Host": result.host_header},
    extensions={"sni_hostname": result.sni} if result.sni else {},
).raise_for_status()

# Other libraries may have different ways of specifying SNI and custom Host headers.
# See also: https://stackoverflow.com/a/77743443

Contact

Talk to me in my matrix room: #ontopic:timedout.uk.

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

resolvematrix-1.0.0a1.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

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

resolvematrix-1.0.0a1-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file resolvematrix-1.0.0a1.tar.gz.

File metadata

  • Download URL: resolvematrix-1.0.0a1.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for resolvematrix-1.0.0a1.tar.gz
Algorithm Hash digest
SHA256 f43f2c34901b5735b09706ed396dfdd5dae755aaae830ceb739f882a1fbe2cb2
MD5 5146a97d26cda1ff4fc1b2d9e1efbac9
BLAKE2b-256 78da0d677845697903824b09c2b1664bae6231443cf097d4d78673c5bea82098

See more details on using hashes here.

File details

Details for the file resolvematrix-1.0.0a1-py3-none-any.whl.

File metadata

File hashes

Hashes for resolvematrix-1.0.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 cc43f0292adcc337e813bd219f06ed3d2b9ad884fbe3bdf87a1e7d2d5cd7a24a
MD5 e6a33fdfbc7f39db97aa4c57f703b0f1
BLAKE2b-256 28c3c59083be8355f86e713a8ed4c69b343b70f95d302a6dd6733fbac94854a8

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