> For the complete documentation index, see [llms.txt](https://docs.pylenium.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pylenium.io/guides/script-with-standalone-pylenium.md).

# Script with Standalone Pylenium

## Setup

Pylenium needs two things in order to be instantiated:

* <mark style="color:orange;">**PyleniumConfig**</mark>
* <mark style="color:orange;">**Pylenium**</mark>

Create a `main.py` file and add the necessary imports:

{% code title="main.py" %}

```python
from pylenium.driver import Pylenium
from pylenium.config import PyleniumConfig
```

{% endcode %}

### Create an instance of PyleniumConfig

Start by creating an instance of PyleniumConfig. Leaving it blank will create a config with default values. **NOTE**: This *<mark style="color:red;">does not</mark>* use <mark style="color:yellow;">**`pylenium.json`**</mark>

{% code title="Default config" %}

```python
from pylenium.driver import Pylenium
from pylenium.config import PyleniumConfig

config = PyleniumConfig()
```

{% endcode %}

To use <mark style="color:yellow;">**`pylenium.json`**</mark>, you'd have to read the file first:

{% code title="Use pylenium.json" %}

```python
import json
from pylenium.driver import Pylenium
from pylenium.config import PyleniumConfig

with open("pylenium.json") as file:
    pylenium_json = json.load(file)

config = PyleniumConfig(**pylenium_json)
```

{% endcode %}

You can set config values directly in the script - mixing and matching as needed

```python
import json
from pylenium.driver import Pylenium
from pylenium.config import PyleniumConfig

with open("pylenium.json") as file:
    pylenium_json = json.load(file)

config = PyleniumConfig(**pylenium_json)
config.browser = "firefox"
```

### Create an instance of Pylenium

Once the config is ready, instantiate Pylenium with it:

```python
from pylenium.driver import Pylenium
from pylenium.config import PyleniumConfig

config = PyleniumConfig()
py = Pylenium(config)
```

## Write your Script

You now have access to Pylenium's many commands to script what you need:

{% code title="Google Search" %}

```python
from pylenium.driver import Pylenium
from pylenium.config import PyleniumConfig

config = PyleniumConfig()
py = Pylenium(config)

py.visit("https://google.com")
py.get("[name='q']").type("pylenium.io\n")
py.should().contain_title("pylenium.io")
py.quit()
```

{% endcode %}

## Run your Script

Use python to execute `main.py`

```bash
python main.py
```


---

# 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://docs.pylenium.io/guides/script-with-standalone-pylenium.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.
