This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
PyTezos β Python toolkit for the Tezos blockchain. Ships two packages from src/:
pytezosβ SDK: RPC client, crypto, operation forging, contract interaction, Michelson parser/interpreter, sandbox runner.michelson_kernelβ Jupyter kernel that wraps the Michelson interpreter.
Two console scripts are installed (see pyproject.toml):
pytezosβpytezos.cli.cli:climichelson-kernelβmichelson_kernel.cli:cli
Requires Python 3.10β3.13 and native libs libsodium, gmp, pkg-config (see README for per-OS install). Dependencies are managed with uv (PEP 621 [project] + PEP 735 [dependency-groups]); uv.lock is committed.
All workflow commands live in the Makefile (run make help for the full list). Highlights:
make installβuv sync --all-extras --all-groups --link-mode symlink --locked. To install without dev deps:uv sync --no-default-groups --locked.make install-depsβ install native deps (libsodium,gmp,pkg-config) for the current OS.make lintβ runsisort,black,ruff, andmypyagainstsrc/,tests/,scripts/. Each is also a standalone target (make ruff,make mypy, etc.). Line length is 120;blackuses single quotes (skip-string-normalization),isortusesforce_single_line.make testβ full local suite. Runs contract/integration/unit tests in parallel withpytest-xdist, thentests/sandbox_testsserially (sandbox tests require Docker and start real Octez nodes viatestcontainers).make test-ciβ emits JUnit XML per suite; sandbox suite only on Linux.make docsβ builds Sphinx docs; depends onmake kernel-docs rpc-docs.rpc-docscallsscripts/fetch_rpc_docs.pyand needsDOCS_RPC_URLpointed at a full node.make imageβ buildspytezos.dockerfileandmichelson-kernel.dockerfile.make updateβuv sync -U --all-extras --all-groupsto bump deps and refreshuv.lock. Thenotebookdependency lives in thejupyterextra; themichelson-kernelDocker image installs it via--extra jupyter, the headlesspytezosimage does not.
Run a single test via uv directly, e.g.:
uv run pytest -xvs tests/unit_tests/test_michelson/test_parse.py::TestParse::test_some_case
Sandbox tests must not be parallelized (they bind ports) β call pytest -xv tests/sandbox_tests/... per make test.
tests/unit_tests/β pure Python, fastest tier; no network, no Docker.tests/contract_tests/β generated from on-chain contracts. Regenerate withmake update-contracts(scripts/fetch_contract_data.pythenscripts/generate_contract_tests.py).tests/integration_tests/β talk to remote RPC endpoints.tests/sandbox_tests/β spin up dockerized Octez nodes viapytezos.sandbox.node. Linux-only in CI.
pytezos/__init__.py exposes pytezos = PyTezosClient() β the canonical entry point. PyTezosClient (in pytezos/client.py) composes ContextMixin + ContentMixin; nearly every higher-level object (operations, contract interfaces, shell queries) is created via self._spawn_context(), which threads an ExecutionContext (pytezos/context/impl.py) through the call chain. When changing client behavior, look at the context layer first β it's the shared state for keys, RPC shell, block hash, chain id, etc.
crypto/βKey(ed25519/secp256k1/p256), signing, mnemonic derivation. Usespysodium,coincurve,fastecdsa.rpc/β HTTP client (shell.py,node.py), typed query tree (query.py), error mapping (errors.py).ShellQueryis the dynamic facade returned bypytezos.shell.operation/β building, forging, signing, injecting operations. Forging logic inpytezos/michelson/forge.pyis shared with Michelson.michelson/β Michelson tooling:parse.py/format.pyβ text β Micheline JSON.forge.pyβ binary forge / unforge (used for both ops and Micheline values).types/β runtime type system (int,pair,map,big_map,ticket,sapling,bls, etc.).instructions/β each Michelson opcode group; called byprogram.pyto walk the stack.sections/βparameter/storage/code/view/tzttop-level sections.repl.pyβInterpreter, the Python reimplementation of the Michelson VM; this is what powers the Jupyter kernel and local contract simulation.program.py,stack.py,micheline.pyβ execution model and AST glue.
contract/β high-level smart-contract surface:ContractInterface(loaded from on-chain address, file, or Michelson source),ContractCall,entrypoint.py,view.py, TZIP-16 metadata.block/,protocol/β block header utilities and protocol diff/upgrade helpers.sandbox/βnode.SandboxedNodeTestCaseand friends launch Octez via Docker (testcontainers); per-protocol parameter JSON lives alongside as<NNN-protohash>-parameters/.parameters.pyholds the protocol-hash constants and selectsLATEST.cli/β Click-basedpytezosCLI (codegen, deploy, sandbox, GitHub integration ingithub.py).
Jupyter kernel that wraps michelson.repl.Interpreter. cli.py provides michelson-kernel install/run. Generated reference docs come from scripts/generate_kernel_docs.py (writes into docs.py) β do not edit docs.py by hand; black skips it via --exclude ".*/docs.py".
(Condensed from CONTRIBUTING.md β read that for the full sandboxed-node flow.)
- Bump
pytezos.sandbox.node.DOCKER_IMAGEto the new Octez image tag. - Add the new protocol hash constant in
pytezos/sandbox/parameters.py, append it toprotocol_hashes/protocol_version, and setLATEST. - Drop the new sandbox
parametersJSON intosrc/pytezos/sandbox/<NNN-protohash>-parameters/(thesandbox-paramsMakefile target copies these out of the officialtezos/tezos:masterimage β note that target uses a hardcoded024-PtTALLiN-parameterspath you'll need to update). - Refresh RPC docs (
DOCS_RPC_URL=... make rpc-docs) and read the protocol release notes for code changes. - Verify with
make allplus a manualpytezos sandbox/michelson-kernel run.
- Branch
aux/X.Y.Z, updateversioninpyproject.toml. make before_release(=make update allβ refreshes deps, lints, tests, docs).- Update
CHANGELOG.mdin the existing format. - Merge to
master, tagX.Y.Z, push tag.