> For the complete documentation index, see [llms.txt](https://0xlava.gitbook.io/ducky-morph/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xlava.gitbook.io/ducky-morph/code-examples/code-transpiration.md).

# Code Transpiration

## Code Transpilation

DuckyMorph supports two ways to transpile DuckyScript into target source code.

* **High-Level API** — recommended for most users.
* **Low-Level API** — provides direct access to the internal components.

### High-Level API

The high-level API uses the `DuckyMorph` facade to handle parsing and code generation.

```python
from duckymorph import DuckyMorph

dm = DuckyMorph()

ast = dm.parse_duckyscript(script_file="payload.ds")

generated_code = dm.generate_code(
    generate="arduino",
    ast=ast
)

print(generated_code)
```

This approach is simple and suitable for most use cases.

***

### Low-Level API

Advanced users can interact directly with the parser and code generators.

```python
from duckymorph.core.ducky_parser import DuckyParser
from duckymorph.core.code_generators.factory import CodeGeneratorsFactory

parser = DuckyParser()

parser.parse("""
GUI r
STRING notepad
ENTER
""")

ast = parser.get_ast()

generator = CodeGeneratorsFactory.get_generator("arduino")

generated_code = generator.generate_code(ast)

print(generated_code)
```

The low-level API provides more control over the transpilation pipeline and is useful for advanced integrations or framework extensions.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://0xlava.gitbook.io/ducky-morph/code-examples/code-transpiration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
