{"id":46324,"library":"secp256k1","title":"secp256k1 Python","description":"Python FFI (Foreign Function Interface) bindings to libsecp256k1, the optimized C library used by Bitcoin for elliptic curve cryptography. Version 0.14.0 wraps libsecp256k1 with secure memory handling (by default) and provides low-level primitives for EC operations, signing, verification, and public key recovery. Release cadence is irregular; maintained by the same author for over a decade.","status":"active","version":"0.14.0","language":"python","source_language":"en","source_url":"https://github.com/rustyrussell/secp256k1-py","tags":["bitcoin","elliptic-curve","cryptography","libsecp256k1"],"install":[{"cmd":"pip install secp256k1","lang":"bash","label":"PyPI install"}],"dependencies":[],"imports":[{"note":"Top-level package; no submodule needed for basic usage.","symbol":"secp256k1","correct":"import secp256k1"}],"quickstart":{"code":"import secp256k1\n\n# Verify a message (example)\nmsg = b\"message\"\n# Generate a random private key (should be securely generated in practice)\nprivate_key = secp256k1.PrivateKey()\nsignature = private_key.ecdsa_sign(msg, raw=True)\n\n# Verify\npublic_key = private_key.pubkey\nverified = public_key.ecdsa_verify(msg, signature, raw=True)\nprint(\"Valid?\", verified)","lang":"python","description":"Creates a PrivateKey, signs a message, then verifies using the public key."},"warnings":[{"fix":"Read the 'About memory safety' section in the README; prefer keys generated via `PrivateKey.random()`.","message":"The PrivateKey constructor does **not** automatically use secure memory unless compiled with libsecp256k1's 'secp256k1_context_create' (default). However, setting `flags=secp256k1.FLAG_SIGN` alone does not enable memory protection. Use `secp256k1.PrivateKey(secp256k1.PrivateKey.random(), raw=True)` for secure key generation.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `private_key.serialize()` (z) and `private_key.deserialize()` (z).","message":"The term 'serialize' and 'deserialize' are spelled with 'z' not 's'. Common to mis-type 'serialise'.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace `All()` with `secp256k1.FLAG_SIGN | secp256k1.FLAG_VERIFY`.","message":"The `secp256k1.All()` and `secp256k1.ALL_FLAGS` constants have been removed in 0.14.0. Use `secp256k1.FLAG_SIGN | secp256k1.FLAG_VERIFY` instead.","severity":"deprecated","affected_versions":"0.14.0"}],"env_vars":null,"search_vec":"'0.14.0':23 'author':55 'bind':8 'bitcoin':17,60 'c':13 'cadenc':48 'cryptographi':21,64 'curv':20,63 'decad':59 'default':31 'ec':39 'ellipt':19,62 'elliptic-curv':61 'ffi':4 'foreign':5 'function':6 'handl':29 'interfac':7 'irregular':50 'key':45 'level':36 'librari':14 'libsecp256k1':10,25,65 'low':35 'low-level':34 'maintain':51 'memori':28 'oper':40 'optim':12 'primit':37 'provid':33 'public':44 'python':2,3 'recoveri':46 'releas':47 'secp256k1':1 'secur':27 'sign':41 'use':15 'verif':42 'version':22 'wrap':24","created_at":"2026-06-07T12:59:21.806634+00:00","updated_at":"2026-06-07T12:59:21.806634+00:00","problems":[{"fix":"Use `secp256k1.FLAG_SIGN | secp256k1.FLAG_VERIFY`.","cause":"The All() constant was removed in 0.14.0.","error":"AttributeError: module 'secp256k1' has no attribute 'All'"},{"fix":"Install libsecp256k1 via your system package manager (e.g., `apt install libsecp256k1-0`) or build from source with `pip install --no-binary :all: secp256k1` to compile statically.","cause":"The libsecp256k1 shared library is not installed on the system or not in LD_LIBRARY_PATH.","error":"OSError: libsecp256k1.so.0: cannot open shared object file: No such file or directory"},{"fix":"Ensure the private key is a 32-byte value less than the secp256k1 curve order (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141). Use `secp256k1.PrivateKey(random_bytes)` where random_bytes is 32 cryptographically random bytes.","cause":"The private key bytes do not satisfy the curve order (e.g., zero or >= n).","error":"ValueError: Invalid secret key"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/rustyrussell/secp256k1-py","github":"https://github.com/rustyrussell/secp256k1-py","docs":null,"changelog":null,"pypi":null,"npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["security"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":null}}