In production you almost never implement BPE yourself. Two libraries cover most of the field.
tiktoken (OpenAI)
Rust-backed BPE tokenizer for the OpenAI encodings: p50k_base (GPT-3), cl100k_base (GPT-4), o200k_base (GPT-4o), o200k_harmony (GPT-5). Fast — about 1M tokens/second on a single core. The Python interface is one import and one method:
Hugging Face tokenizers
A Rust-backed library that supports BPE, WordPiece, and Unigram via SentencePiece. It implements the full pipeline: pre-tokenization (e.g., split on whitespace), normalization (lowercase, NFKC), the model itself (BPE/WordPiece/Unigram), and post-processing (add special tokens, build chat templates). Used internally by AutoTokenizer for almost every Hugging Face model.
Speed: 10-100× faster than pure-Python tokenizers. For training, it can build a vocabulary from a corpus in minutes that would take hours in Python.