Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A Python port of Lua's LPeg pattern matching library

Project Description

PPeg is a pattern matching library for Python, based on Parsing Expression Grammars (PEGs). It’s a port of the LPeg library from Lua.


PPeg is still experimental. The API and semantics are not stable.


Unlike the re module [1], PPeg patterns can handle balanced sequences

>>> from _ppeg import Pattern as P
>>> pattern = P.Grammar('(' + ( (P(1)-P.Set('()')) | P.Var(0) )**0 + ')')
>>> pattern('(foo(bar()baz))').pos
>>> pattern('(foo(bar(baz)').pos
>>> capture = P.Cap(pattern)
>>> capture('(foo(bar()baz))').captures

This example corresponds roughly to the following LPeg example

> lpeg = require "lpeg"
> pattern = lpeg.P{ "(" * ((1 - lpeg.S"()") + lpeg.V(1))^0 * ")" }
> pattern:match("(foo(bar()baz))") -- Lua indexes begin at 1
> pattern:match("(foo(bar(baz)")
> capture = lpeg.C(pattern)
> capture:match("(foo(bar()baz))")
[1]Some regular expression implementations (e.g. PCRE, regex) support recursive patterns, which can match balanced sequences.


  • _cpeg.c
  • _ppeg.c
    • includes lpeg.c
Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
PPeg-0.9.4.tar.gz (46.6 kB) Copy SHA256 Checksum SHA256 Source Nov 15, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting