Add e2b_id: the Python half of the prefixed-ID format - #1628
Conversation
The same format as @e2b/id, name for name: create_id, encode_id, decode_id, parse_id, is_id, create_uuid, encode_bytes/decode_bytes. Standard library only — no dependencies at all, so an ID codec that every service depends on can never be the reason a resolution fails. Agreement with the JS half is enforced rather than asserted. Both suites carry the same golden vectors, computed with base64.b32encode rather than captured from either implementation; both build the same 1303-value corpus from the same seeded LCG; and both pin the same CORPUS_DIGEST over it, so a format change on one side alone fails on both. Each also checks its own codec against an independent reference encoder stated as arithmetic rather than bit shuffling. The one place the surfaces differ is downstream of JavaScript having no UUID type: this package moves uuid.UUID objects where @e2b/id moves canonical hex strings, so decode_id and ParsedId.uuid return UUIDs and there is no uuid_to_bytes/bytes_to_uuid — the standard library already is those. uuids.py and the README both enumerate it. Also wires the two together: the id_tests workflow grows a Python leg, lint and typecheck sync the new uv env, and js-id's docs now name their counterpart. Not published to PyPI. python-sdk publishes via a postPublish script; this package deliberately has none, because pointing one at a project that does not exist with a token that may not be scoped for it would fail `pnpm run publish` and take the whole monorepo's release down. Register the project, confirm the token, then add the script. Co-Authored-By: Claude <noreply@anthropic.com>
PR SummaryLow Risk Overview Cross-language contract: CI: Reviewed by Cursor Bugbot for commit 6da96f9. Bugbot is set up for automated code reviews on this repo. Configure here. |
|
Package ArtifactsBuilt from 9e96c21. Download artifacts from this workflow run. JS SDK ( npm install ./e2b-2.36.2-python-id.0.tgzCLI ( npm install ./e2b-cli-2.16.1-python-id.0.tgzPython SDK ( pip install ./e2b-2.35.0+python.id-py3-none-any.whl |
Stack: 2 of 2, on top of #1627. Review that one first — this PR's diff is the Python package plus the wiring that ties the two halves together.
e2b_idis the same format as@e2b/id, name for name:create_id,encode_id,decode_id,parse_id,is_id,create_uuid,encode_bytes/decode_bytes. Standard library only — no dependencies at all, so an ID codec every service depends on can never be the reason a resolution fails.Part of SDK-303
Usage
InvalidIdExceptioncarries areason("kind" | "prefix" | "length" | "alphabet" | "canonical" | "uuid") andactual_kind, matching the JS side, so callers branch on a field rather than on message prose. It subclassesValueError, so existingexcept ValueErrorguards keep working.How agreement with
@e2b/idis enforced, not assertedThree independent mechanisms, so a format change on one side alone cannot pass on the other:
base64.b32encoderather than captured from either implementation — so they check the code rather than record it.CORPUS_DIGEST: both suites build an identical 1303-value corpus from the same seeded LCG and pin one sha256 over every encoding of it.#1627's suite pipes the whole corpus throughpython3to verify the six-lineb32encodesnippet both READMEs advertise.I also confirmed 300 live-minted IDs round-trip between the built JS bundle and this package across all six kinds.
The one place the surfaces differ
Downstream of JavaScript having no UUID type, this package moves
uuid.UUIDobjects where@e2b/idmoves canonical hex strings:create_uuid(),decode_id()andParsedId.uuidreturn auuid.UUID; the JS counterparts return strings, so a round trip is string-to-string in JS but not here.uuid_to_bytes/bytes_to_uuid—u.bytesanduuid.UUID(bytes=…)already are those.encode_id()accepts either auuid.UUIDor the hex form.uuids.pyand the README both enumerate this. Everything else — names, argument order, failure modes, wire format — is identical.Also in this PR
The wiring the split deferred:
id_tests.ymlgrows a Python leg (uv sync --locked,uv build,pytest),lint.yml/typecheck.ymlsync the new uv env so the recursive root scripts cover it, the root.gitignorepicks up.ruff_cache/, andjs-id's README and test docs now name their counterpart.Not published to PyPI
packages/python-sdkpublishes via apostPublishscript; this package deliberately has none, because pointing one at a project that does not exist — with a token that may not be scoped for it — would failpnpm run publishand take the whole monorepo's release down with it. Register thee2b_idproject, confirmPYPI_TOKENcovers it, then add the same line python-sdk has.Verification
102 tests, plus
ruff,tyanduv buildclean. TheID Package Testsworkflow runs both halves on ubuntu-22.04 and windows-latest with no secrets.🤖 Generated with Claude Code