Metadata-Version: 2.4
Name: vercel-mesh
Version: 0.1.0
Summary: Mesh-aware service-to-service helpers for Vercel Python
License: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: httpx>=0.27.0
Requires-Dist: vercel>=0.5.2

# Vercel Mesh for Python

`vercel-mesh` is a thin `httpx`-shaped layer for service-to-service calls over
Vercel Mesh.

It automatically resolves the current Vercel OIDC token and sends it as
`x-vercel-trusted-oidc-idp-token` so one service can call another through Mesh
without manually wiring auth headers.

## Installation

```bash
pip install vercel-mesh
```

## Sync usage

```python
import os

import vercel.mesh as mesh

response = mesh.get(os.environ["PAYMENTS_API_BASE_URL"])
response.raise_for_status()
data = response.json()
```

## Async usage

```python
import os

import vercel.mesh as mesh

async with mesh.AsyncClient() as client:
    response = await client.get(os.environ["PAYMENTS_API_BASE_URL"])
    response.raise_for_status()
    data = response.json()
```

## Reusing a client

```python
import os

import vercel.mesh as mesh

with mesh.Client(timeout=10.0) as client:
    response = client.post(os.environ["PAYMENTS_API_BASE_URL"], json={"ok": True})
```

`vercel.mesh.Client` and `vercel.mesh.AsyncClient` subclass `httpx.Client` and
`httpx.AsyncClient`, so methods like `get`, `post`, `request`, `build_request`,
`send`, and `stream` all work as expected.

## Raw httpx

If you already have your own `httpx` client, reuse the auth layer directly:

```python
import httpx

from vercel.mesh import TrustedOidcAuth

auth = TrustedOidcAuth()

async with httpx.AsyncClient(auth=auth) as client:
    response = await client.get("https://example.vercel.app")
```

## Framework context

When this code runs inside a Vercel Function, the package reads the incoming
`x-vercel-oidc-token` header via `vercel.headers.set_headers(...)`, just like
the existing `vercel.oidc` helpers.

```python
from collections.abc import Callable

from fastapi import FastAPI, Request
from vercel.headers import set_headers

app = FastAPI()


@app.middleware("http")
async def vercel_context_middleware(request: Request, call_next: Callable):
    set_headers(request.headers)
    return await call_next(request)
```

If no request-scoped token is available, `vercel-mesh` falls back to the same
local refresh and environment variable behavior as `vercel.oidc`.

Responses are standard `httpx.Response` objects.
