MCPcopy Create free account
hub / github.com/apify/impit / stream

Method stream

impit-python/src/async_client.rs:326–369  ·  view source on GitHub ↗
(
        &self,
        py: Python<'python>,
        method: &str,
        url: String,
        content: Option<Vec<u8>>,
        data: Option<RequestBody>,
        headers: Option<HashMap<String, St

Source from the content-addressed store, hash-verified

324
325 #[pyo3(signature = (method, url, content=None, data=None, headers=None, timeout=Some(Right(USE_CLIENT_DEFAULT_SENTINEL)), force_http3=false))]
326 pub fn stream<'python>(
327 &self,
328 py: Python<'python>,
329 method: &str,
330 url: String,
331 content: Option<Vec<u8>>,
332 data: Option<RequestBody>,
333 headers: Option<HashMap<String, String>>,
334 timeout: Option<Either<f64, &str>>,
335 force_http3: Option<bool>,
336 ) -> Result<pyo3::Bound<'python, PyAny>, PyErr> {
337 let response = self.request(
338 py,
339 method,
340 url,
341 content,
342 data,
343 headers,
344 timeout,
345 force_http3,
346 Some(true),
347 )?;
348
349 let fun: Py<PyAny> = PyModule::from_code(
350 py,
351 c_str!(
352 "def wrap_with_context_manager(response):
353 class AsyncContextManager:
354 async def __aenter__(self):
355 self.response = await response
356 return self.response
357 async def __aexit__(self, exc_type, exc_value, traceback):
358 await self.response.aclose()
359 return AsyncContextManager()"
360 ),
361 c_str!(""),
362 c_str!(""),
363 )?
364 .getattr("wrap_with_context_manager")?
365 .into();
366
367 let wrapped_response = fun.call1(py, (response,))?;
368 Ok(wrapped_response.into_bound(py))
369 }
370
371 #[pyo3(signature = (method, url, content=None, data=None, headers=None, timeout=Some(Right(USE_CLIENT_DEFAULT_SENTINEL)), force_http3=false, stream=false))]
372 pub fn request<'python>(

Calls 1

requestMethod · 0.45

Tested by 8

test_readMethod · 0.76
test_iter_bytesMethod · 0.76
test_read_after_closeMethod · 0.76
test_two_read_callsMethod · 0.76