Skip to main content

pymasque

pymasque is a minimal implementation of a Cloudflare Warp MASQUE client in Python, powered by qh3.

It only implements the L4 mode of the MASQUE proxy. This is faster and does not require a userspace IP stack, but only supports TCP.

Installation

Install it as a library:

pip3 install pymasque

Install it with a built-in SOCKS5 proxy:

pip3 install pymasque[socks]

Usage

SOCKS5 Proxy Mode

Use the SOCKS5 proxy mode to launch a SOCKS5 server that proxies all connections over Warp:

$ python3 -m pymasque.socks -h
usage: pymasque.socks [-h] [--host HOST] [--port PORT] [--auth AUTH] [--log-level {DEBUG,INFO,WARNING,ERROR}]
                      [--log-format {text,json}]

SOCKS5 proxy routing through Cloudflare WARP/MASQUE

options:
  -h, --help            show this help message and exit
  --host HOST           bind address
  --port PORT           bind port
  --auth AUTH           username:password
  --log-level {DEBUG,INFO,WARNING,ERROR}
  --log-format {text,json}

On first run, a new Cloudflare Warp account will be created, the details of which will be cached to the disk.

As a Library

pymasque is easy to integrate into your asyncio applications.

Basic Example:

import asyncio
import pymasque

async def main():
  warp = pymasque.WarpConnection()
  stream = await warp.open_stream("cloudflare.com", 80)

  #send an http/1.1 payload
  payload = "GET /cdn-cgi/trace HTTP/1.1\r\nHost: cloudflare.com\r\nConnection: keepalive\r\n\r\n"
  await stream.send(payload.encode())
  response = await stream.recv()
  print(response.decode())

asyncio.run(main())

pymasque.WarpConnection and pymasque.WarpStream contain all that you need for sending TCP traffic over Cloudflare workers.

Creating New MASQUE Connections:

Creating a new pymasque.WarpConnection object and calling .connect() on it will create a new MASQUE connection to Cloudflare Warp.

You don't need to explicitly call .connect(), it will automatically run when you create the first stream.

warp = pymasque.WarpConnection()
await warp.connect()

Creating New Streams:

Streams can be created by calling WarpConnection.open_stream(hostname, port). The hostname can be any domain name, IPv4 address, or IPv6 address. If a domain name is provided, it will be resolved locally using the system DNS resolver. This will return a pymasque.WarpStream object.

warp = pymasque.WarpConnection()
stream = await warp.open_stream("example.com", 1234)

Once you have your stream object, you may call stream.recv() or stream.send(data) to recieve or send data. The data sent must be a bytes object.

await stream.send(b"hello world")
response = await stream.recv()

License

This project is licensed under the GNU LGPL v3.

This license is mainly applied to libraries. You may copy, distribute and modify the software provided that modifications are described and licensed for free under LGPL. Derivatives works (including modifications or anything statically linked to the library) can only be redistributed under LGPL, but applications that use the library don't have to be.

- From tldrlegal.com

Metadata

Release files for pymasque 0.1.1

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

Source distribution (sdist)

Source distribution for pymasque 0.1.1
File Size Uploaded Provenance Actions
pymasque-0.1.1.tar.gz 10.1 kB Without provenance Details for pymasque-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pymasque 0.1.1
File Interpreter ABI Platform Actions
pymasque-0.1.1-py3-none-any.whl Python 3 none any Details for pymasque-0.1.1-py3-none-any.whl

Total release size: 20.5 kB

Release files / pymasque-0.1.1.tar.gz

Download URL pymasque-0.1.1.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3c30213bbe954d97d89afe67c3fd47d1d49735896e3619368f9ed994f6dda8a3
BLAKE2b-256 checksum
How to use checksums
0cc14210c8c33ae23c93c673cf389d4463fc529ec3f68947453fa29d6b02f725
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / pymasque-0.1.1-py3-none-any.whl

Download URL pymasque-0.1.1-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
408aa7ba37905f3d6805af8d02d88fad417147991fd83e71fb5178083ef6c600
BLAKE2b-256 checksum
How to use checksums
864de5379c2e0070f52be71262decc301e38585c6fee7d947615fd5e0f662981
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for pymasque 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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