安全的默认值
默认验证 TLS 证书,各阶段超时为五秒,重定向由你决定是否开启。
import req
def main() raises:
var response = req.get("https://example.com")
response.raise_for_status()
print(response.status_code)
print(response.text())
import req
def main() raises:
var owner = req.Client(base_url="https://example.com/")
with owner.context() as client:
var response = client.get("/")
response.raise_for_status()
print(response.text())
import req
def main() raises:
with req.stream("GET", "https://example.com") as body:
body.raise_for_status()
while True:
var chunk = body.read_chunk(65536)
if not chunk:
break
print(len(chunk.value()))
小而清晰的 API,让请求、响应和资源管理各就其位。
默认验证 TLS 证书,各阶段超时为五秒,重定向由你决定是否开启。
复用连接,在一个客户端中管理请求头、认证和有作用域的 Cookie。
发送 JSON、表单、字节或 multipart 文件,读取文本、结构化 JSON 或原始响应内容。
按需分块读取响应体,增量解码 gzip 和 deflate。
pixi workspace channel add --prepend https://repo.prefix.dev/modular-community
pixi add req