---
title: "e2b-dockerfile-utils | pypx"
description: "E2B Dockerfile utils - Dockerfile parser, shell lexer and .dockerignore matcher ported from BuildKit and Moby"
canonical_url: "https://pypx.app/packages/e2b-dockerfile-utils"
meta:
  "og:description": "E2B Dockerfile utils - Dockerfile parser, shell lexer and .dockerignore matcher ported from BuildKit and Moby"
  "og:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_e2b-dockerfile-utils%2Cversion_0.1.2%2Csummary_~RTJCIERvY2tlcmZpbGUgdXRpbHMgLSBEb2NrZXJmaWxlIHBhcnNlciwgc2hlbGwgbGV4ZXIgYW5kIC5kb2NrZXJpZ25vcmUgbWF0Y2hlciBwb3J0ZWQgZnJvbSBCdWlsZEtpdCBhbmQgTW9ieQ%2Clicense_Apache-2.0%2Cp_Ii9wYWNrYWdlcy9lMmItZG9ja2VyZmlsZS11dGlscyI%2Cs_gBDsmNKA-kHW_df4.png"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "e2b-dockerfile-utils 0.1.2"
  "twitter:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_e2b-dockerfile-utils%2Cversion_0.1.2%2Csummary_~RTJCIERvY2tlcmZpbGUgdXRpbHMgLSBEb2NrZXJmaWxlIHBhcnNlciwgc2hlbGwgbGV4ZXIgYW5kIC5kb2NrZXJpZ25vcmUgbWF0Y2hlciBwb3J0ZWQgZnJvbSBCdWlsZEtpdCBhbmQgTW9ieQ%2Clicense_Apache-2.0%2Cp_Ii9wYWNrYWdlcy9lMmItZG9ja2VyZmlsZS11dGlscyI%2Cs_gBDsmNKA-kHW_df4.png"
---

> Index of every page on this site: [llms.txt](https://pypx.app/llms.txt)

# **e2b-dockerfile-utils**

v0.1.2

E2B Dockerfile utils - Dockerfile parser, shell lexer and .dockerignore matcher ported from BuildKit and Moby

19 KB Python 3.11+ py3-none-anyApache-2.0

[** Diff **](https://pypx.app/packages/e2b-dockerfile-utils/diff)

`$ uv add e2b-dockerfile-utils`

# e2b-dockerfile-utils

Dockerfile parser and shell lexer ported from [BuildKit](https://github.com/moby/buildkit/tree/master/frontend/dockerfile) and a `.dockerignore` matcher ported from [moby/patternmatcher](https://github.com/moby/patternmatcher), with no runtime dependencies. Used by the [E2B SDK](https://pypi.org/project/e2b/) to implement `Template.from_dockerfile` and to filter the build context.

```
from e2b_dockerfile_utils import ShellLex, parse_dockerfile_ast

ast = parse_dockerfile_ast(
    """
FROM node:24 AS build
ENV KEY="a  b" OTHER=c
RUN <<EOF
npm ci
npm run build
EOF
"""
)

for instruction in ast.instructions:
    print(instruction.name, instruction.flags, instruction.args)

lex = ShellLex(ast.escape_token)
lex.process_words('KEY="a  b" OTHER=c')  # ['KEY=a  b', 'OTHER=c']
```

`parse_dockerfile_ast` handles parser directives (`# escape=`, `# syntax=`), comments (including inside line continuations), builder flags, JSON/exec forms and heredocs, and reports line numbers and warnings. `ShellLex` splits and unquotes words the way BuildKit does, preserving `$VAR` / `${VAR:-default}` references for later expansion.

```
from e2b_dockerfile_utils import PatternMatcher

matcher = PatternMatcher(["node_modules", "*.log", "!keep.log"])
matcher.matches("node_modules/pkg/index.js")  # True
matcher.matches("keep.log")  # False
```

`PatternMatcher` applies `.dockerignore` semantics to slash-separated paths relative to the context root: a pattern matching a directory excludes everything under it, and `!` patterns re-include paths (the last matching pattern wins). An invalid pattern raises a plain `ValueError`.

## **Details **

<dl>

<dt>Version</dt>
<dd>0.1.2</dd>

<dt>License</dt>
<dd>Apache-2.0</dd>

<dt>Python</dt>
<dd>&gt;=3.11</dd>

<dt>Maintainer</dt>
<dd>e2b</dd>

</dl>

## **Links**

- [Bug Tracker](https://github.com/e2b-dev/e2b/issues)
- [Homepage](https://e2b.dev/)
- [Repository](https://github.com/e2b-dev/e2b/tree/main/packages/dockerfile-utils-python)
- [View on PyPI](https://pypi.org/project/e2b-dockerfile-utils/)

## **Release Cadence **

**3**

releases in the past year

avg 18 days between releases

## **Maintainers **

- e2b · [hello@e2b.dev](mailto:hello@e2b.dev)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://pypx.app/#website","@type":"WebSite","description":"The Python Package Index, reimagined. Fast search, dependency insights, download trends, and changelogs — all in one place.","name":"pypx","url":"https://pypx.app/"},{"@id":"https://pypx.app/packages/e2b-dockerfile-utils#webpage","@type":"WebPage","description":"E2B Dockerfile utils - Dockerfile parser, shell lexer and .dockerignore matcher ported from BuildKit and Moby","name":"e2b-dockerfile-utils","url":"https://pypx.app/packages/e2b-dockerfile-utils","isPartOf":{"@id":"https://pypx.app/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://pypx.app/packages/e2b-dockerfile-utils"]}]},{"@id":"https://pypx.app/packages/e2b-dockerfile-utils#/schema/software-application/1","@type":"SoftwareApplication","applicationCategory":"DeveloperApplication","description":"E2B Dockerfile utils - Dockerfile parser, shell lexer and .dockerignore matcher ported from BuildKit and Moby","license":"Apache-2.0","name":"e2b-dockerfile-utils","softwareVersion":"0.1.2"}]}
```

## Sitemap

See the full [sitemap](https://pypx.app/sitemap.md) for all pages.
