Skip to main content

Python bindings for yescrypt using a tiny Go shared library

Project description

pyyescrypt

Python bindings for yescrypt, implemented as a small Go shared library loaded via ctypes.

No CPython C extension code. The Python package is pure Python, plus a platform-specific shared library:

  • macOS: libyescrypt.dylib
  • Linux (glibc): libyescrypt.so

Windows is currently unsupported because the Go-based build has only been validated on macOS and glibc-based Linux.

Public API

import pyyescrypt

hash_str = pyyescrypt.generate_hash("my password")
ok = pyyescrypt.verify_hash("my password", hash_str)
  • generate_hash(password: str) -> str returns a modular-crypt yescrypt hash string (typically starts with $y$).
  • verify_hash(password: str, hash_str: str) -> bool verifies a password against a stored hash string.

Errors raised from the native layer become ValueError in Python.

Command-line interface

Installing pyyescrypt also provides a pyyescrypt-cli executable (packaged Go binary). It exposes the same operations as the Python module:

# Generate a hash (reads the password from stdin)
printf "secret" | pyyescrypt-cli generate

# Verify returns exit status 0 on success and prints "1"
printf "secret" | pyyescrypt-cli verify --hash '$y$...'

The Python package automatically falls back to this CLI whenever the shared library cannot be loaded (for example on musl-based systems), and you can force it via PYYESCRYPT_BACKEND=cli.

Repo layout

  • capi/ Go code compiled as a C-shared library (-buildmode=c-shared)
  • src/pyyescrypt/_native.py loads the shared library with ctypes and exposes the Python API
  • src/pyyescrypt/_native/ destination directory for the built shared library
  • tests/ Python tests (ABI-level tests via ctypes)

Requirements

  • Go toolchain available on PATH
  • Python 3.10+ required
  • On macOS, Xcode Command Line Tools installed (xcode-select --install)

Build the native library

make native

This builds the shared library into:

  • src/pyyescrypt/_native/libyescrypt.dylib on macOS
  • src/pyyescrypt/_native/libyescrypt.so on Linux

To build the bundled CLI (used automatically on musl) run:

make cli

which outputs src/pyyescrypt/_cli/pyyescrypt-cli.

Run tests

make test

This will:

  • run go test -cover ./...
  • create a local virtualenv at .venv
  • install test dependencies into the venv
  • build the native library
  • run pytest

If you want only the Python tests:

make py-test

Development notes

Why ctypes instead of a CPython extension

CPython extension modules require a C ABI boundary anyway. This project avoids the CPython C-API completely by exporting a small C ABI from Go and calling it from Python using ctypes.

Memory ownership

Native functions return char* allocated by the native library. Python must free them by calling yc_free. The Python wrapper handles this.

Linux libc notes

glibc-based distros (manylinux wheels) are fully supported today. Musl-based systems such as Alpine cannot load the Go-built shared library because Go currently emits initial-exec TLS relocations for -buildmode=c-shared, which musl's dynamic loader refuses. Installing the wheel on Alpine succeeds, but the native backend fails to import.

The package now ships a small Go CLI binary that the Python module falls back to automatically whenever the native backend cannot be loaded (or when PYYESCRYPT_BACKEND=cli is set). Set PYYESCRYPT_BACKEND=native if you prefer to fail fast when the shared library is unavailable.

Packaging

The wheel must include the shared library under pyyescrypt/_native/.

For local development, make native places the library in the repo tree where the tests expect it.

To validate packaging, use a separate workflow:

  1. build a wheel
  2. install it into a clean venv
  3. import pyyescrypt and run the tests against the installed package data

License

See LICENSE.

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

pyyescrypt-0.1.15.tar.gz (23.9 kB view details)

Uploaded Source

Built Distributions

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

pyyescrypt-0.1.15-cp314-cp314-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

pyyescrypt-0.1.15-cp314-cp314-manylinux_2_34_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

pyyescrypt-0.1.15-cp314-cp314-macosx_12_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.14macOS 12.0+ ARM64

pyyescrypt-0.1.15-cp313-cp313-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

pyyescrypt-0.1.15-cp313-cp313-manylinux_2_34_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

pyyescrypt-0.1.15-cp313-cp313-macosx_12_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.13macOS 12.0+ ARM64

pyyescrypt-0.1.15-cp312-cp312-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pyyescrypt-0.1.15-cp312-cp312-manylinux_2_34_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

pyyescrypt-0.1.15-cp312-cp312-macosx_12_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 12.0+ ARM64

pyyescrypt-0.1.15-cp311-cp311-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pyyescrypt-0.1.15-cp311-cp311-manylinux_2_34_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

pyyescrypt-0.1.15-cp311-cp311-macosx_12_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.11macOS 12.0+ ARM64

pyyescrypt-0.1.15-cp310-cp310-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

pyyescrypt-0.1.15-cp310-cp310-manylinux_2_34_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

pyyescrypt-0.1.15-cp310-cp310-macosx_12_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.10macOS 12.0+ ARM64

File details

Details for the file pyyescrypt-0.1.15.tar.gz.

File metadata

  • Download URL: pyyescrypt-0.1.15.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.1.dev37+g4f20c0dc3 CPython/3.12.3

File hashes

Hashes for pyyescrypt-0.1.15.tar.gz
Algorithm Hash digest
SHA256 7f41aa55cee1fe3f19515e3470b52716c82f800d3f1b3913fc6526ce50b60fbf
MD5 f2e14705a202d3838a1994c9d8d5b01f
BLAKE2b-256 4c436d9ce23e430a09206f18ec41f008caa71c73a96fa7692e80fd15f0a5bdb9

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d90c59803d9c54812fc633aab1b6ffe550ebe364f8a26703e2a3878729678639
MD5 3701d5e419cf3b4a95415c1f60acfa38
BLAKE2b-256 0c882bba2876aef293fd2bb8eb365e1b6e4fd86d80374413b2eed395f8a64866

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 118e25a0e212ea3883dc5d2688b5182fc50e1da275ba260d8dd46410a1366f60
MD5 773c781b0aa60325db8a3f41d75b8f8e
BLAKE2b-256 968e1b481c05dc32fabbb491a9e71e59e353c7bd77afba1c2651c59ec8089940

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp314-cp314-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp314-cp314-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 c2d95a32e7d2c1caa82cdd97435f9d038118e537865ba52d70e21733edab81d6
MD5 729a2e440d85981e94d032df02e80f5d
BLAKE2b-256 9a6481a017465a0e640adc92ef2d451f0b21cc575da0d627275cfe21c9fb8798

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0d8bcf5a9865147640320012a306f07e78aa838d7070deaf9abf305f0fe1dc0d
MD5 c10feb6c509793a653c9449cca0ee87f
BLAKE2b-256 4fcd7455a17827c836353f72613679169cee829c354141ab4c95e3dc3f7f7fbd

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f05407d1206220e8d56c433b0accdb54cf25701d3807d62de8e556a9f5bbdad4
MD5 9d87c5bcbaec09233dfcc9d40a3030a4
BLAKE2b-256 1e80b73fe3e985d70b2118fd7dc316eda732b4074f42218786ee084274f14dce

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp313-cp313-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp313-cp313-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 f7d2b0e266422dd2eb6dc012c772019980c5a1bee8bc01a3f3cb42ea056ce7ab
MD5 977342bf3bc9d6216bca48913351151d
BLAKE2b-256 0cdf93fc3679601d941cd80f7dd17d2cd5d60b0b87b4bf9f2c7be167bcc128ec

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a7e1117b246b7eb1a02342388d6bd5143d88f5a997577f153e4dfdf30435e029
MD5 14b29745d0fdb758dd51e0ddcc0a2a3d
BLAKE2b-256 32490c64b8124a183fd494e2bf7c022227bbea80812b2596e9fba38d0f025233

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 760a1b02e770fc16cd9a75d1d441053ad416796887840e3d536dc712927bb20d
MD5 6aefd69c4595d879c776992c8b3b79c4
BLAKE2b-256 3f367a414126390959afcbcb81e63860f519075ca56baff125d2e560f854e926

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp312-cp312-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp312-cp312-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 ade2c9279bb671688d258f20838d2d23df6f094fdd9cd4f9172ecf0379bc6667
MD5 a38abcc6884ab02d4c52138a834a7e83
BLAKE2b-256 aa965b04d2d293a8150f8efa4e8bdf539ebf6e44fe2a1026cdbc46be630e1a15

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ffd42139ed2a8090d6415199a7248449870f6dc1bcf4a5bd2d42e14de0b86ae7
MD5 1ebb4855e58b27462dd712ee4405f8c4
BLAKE2b-256 e3f9ee43ea8dbe67d43343f342332790cacfc115b34836ce088d8f05d169837b

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c40ace49f07902172a6135224dc226dcccc0e3bb4ddd824387d823f866490ded
MD5 de124bcda4fe4a69b6f10409153fa6fc
BLAKE2b-256 3d7fa0d858a9e20297bb78e8b8f16cc48dbc1783a9061eb8f3bd62008b9f771c

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp311-cp311-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp311-cp311-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 1ea034ed3b3202dda782354fb1241d7b0d7b7bd05ca17aefe15e9e6704555004
MD5 f3773b3c6ee249924c5cb343bc4b98d8
BLAKE2b-256 3d940e8ae6378f904895e61a033149d05b55aa3a0ed64cec3ca5437c7c996aaa

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5bf8d7815561b31f4cb8c85fbb8759258b87e6200e1d7d7693ec8f0a4658b3b9
MD5 bb1a7adb3ff04db82b4fa81f9f395b5f
BLAKE2b-256 a66807250f79d00e96ed76bd1da212f8d5c81aad683c75166a8579611a844fa5

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4284e5ee705c4fd2c4fea19b82196a71b0bb5d75624a297ce78cd8333e2dc089
MD5 0bf55ee48053cd3e85cbf543a7eaa214
BLAKE2b-256 34936faf0120ab9c8bc2cce3e65df19dfe593cc9efed73287d86c9ec532815f8

See more details on using hashes here.

File details

Details for the file pyyescrypt-0.1.15-cp310-cp310-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pyyescrypt-0.1.15-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 293dd080b0dd42bb019e0d1dab8995d7588ad27e40783668b82b9f05318a2637
MD5 5f07485e9f7dce886fa6674480b3ff51
BLAKE2b-256 140bd8297cfa021540f416c9e0e9ce3167f2597bf59e22c7d6f20eaa6db50a23

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