> ## Documentation Index
> Fetch the complete documentation index at: https://docs.context.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Python

> Install the Python SDK, scrape a webpage, and retrieve brand data.

The [Python SDK](https://pypi.org/project/context.dev/) requires Python 3.9 or newer.

## Install the SDK

Create and activate a virtual environment:

```bash theme={null}
python3 -m venv .venv
source .venv/bin/activate
```

Then install the SDK:

```bash theme={null}
python -m pip install context.dev
```

## Set your API key

Get a secret API key from the [dashboard](https://context.dev/dashboard). Set it in the terminal where you will run the example:

```bash theme={null}
export CONTEXT_DEV_API_KEY="ctxt_secret_..."
```

Keep the key in server-side code. Do not expose it in a browser or commit it to source control.

## Scrape a webpage

Save this as `scrape.py`:

```python scrape.py theme={null}
import os
from context.dev import ContextDev

client = ContextDev(api_key=os.environ["CONTEXT_DEV_API_KEY"])

response = client.web.web_scrape_md(
    url="https://example.com",
    use_main_content_only=True,
)

print(response.markdown)
```

Run it with the same Python environment:

```bash theme={null}
python scrape.py
```

## Check the result

The example prints the page content as Markdown. Look for the `Example Domain` heading; the remaining text and formatting may vary.

```markdown Expected heading theme={null}
# Example Domain
```

If you receive an error, check the key and request details in [Troubleshooting](/optimization/troubleshooting). See the [Markdown API reference](/api-reference/web-scraping/markdown) for all parameters and response fields.

## Retrieve brand data

Replace the request and final `print` with this lookup. It prints the matched company name.

```python theme={null}
response = client.brand.retrieve(
    type="by_domain",
    domain="stripe.com",
)

print(response.brand.title)
```

## Next steps

<CardGroup cols={2}>
  <Card title="Scrape a webpage" icon="globe" href="/guides/scrape-websites-to-markdown">
    Choose which page content to include.
  </Card>

  <Card title="Retrieve brand data" icon="palette" href="/guides/get-brand-data">
    Look up profiles with other company identifiers.
  </Card>
</CardGroup>
