PKT-BUILDER
English | Русский
Builds a working .pkt file for Cisco Packet Tracer from a YAML description,
and does the reverse: exports an existing .pkt to YAML.
The screenshot shows 8lab.pkt, built by this tool from
examples/lab8.yml and opened in Packet Tracer 9.0.0
without any errors.
pkt-builder -c configs\configuration.yml -i projects\my_new.pkt
pkt-builder --export 9lab.pkt -o 9lab.yml
Installation
pip install pkt-builder
Or from source (editable):
git clone https://github.com/nsaBogdan54/PKT-BUILDER.git
cd PKT-BUILDER
pip install -e .
After installation you get the pkt-builder console command
(on Windows it is Scripts\pkt-builder.exe). It works from any directory:
pkt-builder -c configs\configuration.yml -i projects\my_new.pkt
pkt-builder --export 9lab.pkt -o 9lab.yml
pkt-builder --help
How paths are resolved:
-c/-i/--export/-o— relative to the current directory;seed:in the YAML — relative to the directory of the.ymlfile itself (an absolute path is used as is);- the bundled donors (
lab3_donor.pkt,lab7_donor.pkt) come from inside the package, so the examples and the export work without any external files.
There are no dependencies: PyYAML is used if it is installed, otherwise the
built-in miniyaml.py takes over. All you need is Python 3.10+.
pip install pkt-builder[yaml] # + PyYAML (faster and stricter)
You can also run it without installing, straight from the repository root:
python -m pkt_builder -c examples\lab8.yml -i 8lab_new.pkt
python pkt_builder.py -c examples\lab8.yml -i 8lab_new.pkt
Both do exactly the same as pkt-builder. The old form
python pkt_builder\pkt_builder.py will not work: pkt_builder is a package,
and the CLI lives inside it (cli.py).
Setting PKT_BUILDER_YAML=mini in the environment forces the built-in parser.
That is handy for checking that your config does not depend on PyYAML.
Structure
pkt_builder/ repository root
├─ pkt_builder/ package (pkt-builder / python -m pkt_builder)
│ ├─ __main__.py entry point for -m
│ ├─ cli.py CLI: argument parsing, build, export
│ ├─ config.py YAML schema and validation
│ ├─ builder.py LabSpec -> .pkt
│ ├─ exporter.py .pkt -> YAML
│ ├─ ports.py port catalog and name abbreviations
│ ├─ verify.py structural check of the result
│ ├─ resources.py access to the bundled donors and pt_accept.ps1
│ ├─ miniyaml.py dependency-free YAML parser
│ ├─ data/ lab3_donor.pkt, lab7_donor.pkt, 8lab_result.pkt, pt_accept.ps1
│ └─ _vendor/pkt_core/ .pkt library (GPL-3.0-or-later):
│ ├─ builder/ add_device / link / prune_seed_devices / save
│ ├─ codec/ read and write the .pkt container (zlib + XML)
│ ├─ crypto/ payload signing and encryption
│ └─ data/ device_templates.json, network_seed.xml
├─ pkt_builder.py wrapper: python pkt_builder.py == pkt-builder
├─ build_8lab.py script that produced the reference 8lab.pkt
├─ 8lab.pkt reference result (accepted by PT 9.0.0)
├─ pyproject.toml package metadata, the pkt-builder entry point
├─ examples/ sample YAML files
├─ tests/ unit tests
├─ tools/ verify_8lab.py
└─ docs/ format, schema, validation
Command-line options
| Option | Meaning |
|---|---|
-c, --config |
input .yml (build mode) |
-i, --input |
output .pkt (build mode); -o is an alias for it |
--export PKT |
export a .pkt to YAML (instead of building) |
-o, --output |
output .yml for --export (defaults to next to the .pkt); in build mode an alias for -i |
--export-seed |
what to write into seed: (default: the exported file itself) |
-s, --seed |
donor .pkt used as a template (default: the bundled lab3_donor.pkt) |
--check-only |
validate the config and print the plan, write nothing |
--no-verify |
skip the structural check of the result |
--accept |
also open the file in Packet Tracer (about 60 s, Windows only) |
-q / -v |
quiet mode / print every config line and port decision |
Paths understand ~, %USERPROFILE% and $HOME.
Exit codes: 0 — success, 1 — config or build error, 2 — Packet Tracer
not found (--accept).
YAML schema
seed: my_donor.pkt # optional, relative to your .yml
defaults: # optional values for all devices
power: true
devices:
- model: 2911 # key from the bundled model template library
name: HQswitch
pos: 200, 235 # "x, y" | [x, y]; omit pos for auto-layout
install: HWIC-2T # a module or a list of modules
power: true
pc_ip: [10.0.0.10, 255.255.255.0, 10.0.0.1] # PC / Server
cfg: |
hostname HQswitch
ip address 10.0.0.1 255.255.255.0
no shutdown
end
links:
- auto: [CMERouter, CMESwitch]
- auto: [CMERouter, RemoteRouter, dce: CMERouter, clock: 64000]
- [CMESwitch, Fa0/2, PH1, Switch]
- [CMESwitch, Fa0/2, PH1, Switch, copper]
- [CMERouter, Serial0/0/0, RemoteRouter, Serial0/0, serial, CMERouter, 64000]
- [CMERouter, s0/0/0, RemoteRouter, s0/0/0, serial, CMERouter]
- [R1, g0/0/0, R2, g0/1, copper]
Devices
model— a key from the bundled model template library (pkt_builder/_vendor/pkt_core/data/device_templates.json):2911,2811,2620XM,3560-24PS,2960-24TT,7960,PC-PT,Server-PT, … .install— a module or a list (HWIC-2T,WIC-2T,NM-4A/S,NIM-2T…). Without a module, a 2811 has noSerial0/0/xports.cfg— lines (a block scalar) or a list of strings; each line is written as in theshow running-configoutput. Leading extra spaces are preserved. Placeholders{{mac:PH1}},{{port_mac:PH1}},{{client_id:PH1}}and{{name}}are supported.{{mac}}/{{client_id}}are the device's own MAC (<ENGINE><BUILD_IN_ADDR>, or the first copper port when the model has no chassis address) — that is what Packet Tracer shows for a phone and whatephone mac-addressmatches.{{port_mac}}is the first port's MAC. Addresses are read from the XML after the devices are created.
Links
Full port form:
[device_a, port_a, device_b, port_b, (kind), (dce), (clock)]
| Form | Meaning |
|---|---|
[A, B] / auto: [A, B] |
pick the cable type and free ports automatically |
auto: [A, B, dce: A, clock: 64000] |
auto-pick, but make it a serial link |
[A, portA, B, portB] |
cable type is inferred from the port names |
[A, portA, B, portB, copper|serial] |
cable type given explicitly |
[.., serial, DCE] |
clock = 64000 by default |
[.., serial, DCE, 64000] |
clock given explicitly |
Three-element links ([A, B, copper]) are rejected as ambiguous.
Port names can be abbreviated: Fa0/2, g0/0/0, s0/0/0. The tool expands
them to the canonical form (FastEthernet0/2, …) and checks that the device
actually has that port. Otherwise Packet Tracer would show
"Incompatible File".
The 7960 phone has two ports with non-standard names: Switch (uplink) and
PC (passthrough): [CMESwitch, Fa0/2, PH1, Switch].
The order "devices → links → configs" is applied automatically, so a
clock rate on a DCE port is not overwritten by the config.
Verifying the result
After a build, a structural check runs without Packet Tracer: the VERSION
tag, the device count, Switch on the 7960, DCEDEV/DCEPORT and clock rate on
serial links, POWER on copper ports, and duplicate cables. The outcome is a
single line VERDICT : structure looks OK or a list of ERRORs.
A real check:
pkt-builder -c examples\lab8.yml -i out.pkt --accept
--accept runs the bundled pt_accept.ps1, which looks for Packet Tracer only
at hard-coded paths:
C:\Program Files\Cisco Packet Tracer 9.0.0\bin\PacketTracer.exe
C:\Program Files\Cisco Packet Tracer 8.2.2\bin\PacketTracer.exe
C:\Program Files (x86)\Cisco Packet Tracer 8.2.2\bin\PacketTracer.exe
If Packet Tracer is installed somewhere else, or you are not on Windows,
--accept exits with code 2 (PacketTracer.exe not found). This is expected:
the build itself does not depend on it. To add your own path, append it to the
$pt array in pkt_builder/data/pt_accept.ps1. The script closes a running
Packet Tracer before the check and after it. If the script itself is missing,
the command prints pt_accept.ps1 not found (--accept is Windows-only) and
returns 2.
Export .pkt → YAML
pkt-builder --export 9lab.pkt -o 9lab.yml
pkt-builder --export 9lab.pkt # -> 9lab.yml next to the .pkt
Everything needed for a rebuild is restored:
model,name,pos(fromWORKSPACE/LOGICAL),install(installed interface cards),power: falsefor powered-off devices,description;cfg— the fullRUNNINGCONFIG, line by line (a|block scalar);- for PC/Server —
pc_ipanddhcp; links— with explicit ports; for serial links,dce(fromDCEDEV) andclock(from the DCE port'sCLOCKRATE);seed:— the path to the source.pkt, because itsVERSIONis guaranteed to open in your Packet Tracer (relative to the output.ymldirectory).
The exported YAML is a normal input file: -c exported.yml -i new.pkt builds
the same topology. This round-trip has been verified — devices, configs and
links match, and the file is accepted by PT 9.0.0.
Examples
| File | What it shows |
|---|---|
examples/lab8.yml |
the full lab 8 (CME + remote site), equivalent to 8lab.pkt |
examples/link_forms.yml |
every way to write links |
examples/end_devices.yml |
PC/Server with pc_ip, auto-layout |
examples/two_sites.yml |
two routers, two switches, a serial link between them |
examples/minimal.yml |
the minimum: one device and a config |
examples/bad_phone_port.yml |
what the phone-port error looks like |
Tests
python -m unittest discover -s tests -p "test_*.py"
The tests build the examples into a temporary directory, so nothing in the
repository is changed. --accept is not part of the test run because it needs
an installed Packet Tracer. Tests that require PyYAML are skipped when it is
missing.
Limitations
- Models whose interface names cannot be derived from a template (hubs, IoT, Cloud-PT) are checked more loosely: the port is accepted as written.
VERSIONcomes from the donor file. If your Packet Tracer is older than the donor, the file will be rejected. Put your own.pktanywhere and pass it as-s path\to\own.pkt(or setseed:in the YAML).- Wireless links (
set_wireless) are not configurable through YAML yet — only cable links are supported. --acceptworks on Windows only (see above).
Disclaimer
- Educational use: This tool was created solely to automate educational lab work and for educational purposes.
- API costs: The author is not responsible for any financial expenses users may incur from third-party APIs (e.g. RouterAI, OpenAI and others) used to generate YAML configs or to run the script.
- Cisco Packet Tracer EULA: Cisco Packet Tracer is proprietary software of
Cisco Systems, Inc. Using this generator must not violate Cisco's End User
License Agreement (EULA). The author is not affiliated with Cisco Systems
and is not responsible for the consequences of using generated
.pktfiles in commercial or production environments.
Acknowledgements
This project uses a modified version of the .pkt decoding and generation
library from
aacanadaa/packet-tracer-pkt-format.
The original code is distributed under the GNU GPLv3, which is why the whole
package is licensed the same way.
License
The project is distributed under the GNU General Public License v3.0 or later (GPL-3.0-or-later). The full text is in LICENSE.
The vendored code in pkt_builder/_vendor/pkt_core/ is a third-party library
pkt_core (© its author), also under GPL-3.0-or-later; its SPDX headers are
kept unchanged. The rest of pkt_builder is under GPL-3.0-or-later as well
(see the # SPDX-License-Identifier: GPL-3.0-or-later header in every module).
Metadata
Release files for pkt-builder 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pkt_builder-0.1.3.tar.gz | 1.0 MB | Without provenance | Details for pkt_builder-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pkt_builder-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for pkt_builder-0.1.3-py3-none-any.whl |
Total release size: 2.1 MB
Release files / pkt_builder-0.1.3.tar.gz
| Download URL | pkt_builder-0.1.3.tar.gz |
|---|---|
| Size | 1.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
657662acbb51c9d626f55147424b75237faf0007c12d2e091bc3df280e6beef1
|
|
BLAKE2b-256 checksum How to use checksums |
75c6fe74f94e574dd73b9424aae907c51ebd24a01260c1a27fb465fd46a553f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / pkt_builder-0.1.3-py3-none-any.whl
| Download URL | pkt_builder-0.1.3-py3-none-any.whl |
|---|---|
| Size | 1.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9f3193d7ece546423b22bfe66f9ab96afabbfd741dbd7562e62d1800a6fd5728
|
|
BLAKE2b-256 checksum How to use checksums |
6224dd30d7d9d7c9d7c019f1b1a2ca1257e7caa937c5c7767337de2907f7f683
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for pkt-builder 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.