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

Method new

impit-python/src/client.rs:40–128  ·  view source on GitHub ↗
(
        py: Python<'_>,
        browser: Option<String>,
        http3: Option<bool>,
        proxy: Option<String>,
        timeout: Option<Either<f64, &str>>,
        verify: Option<bool>,
       

Source from the content-addressed store, hash-verified

38 #[new]
39 #[pyo3(signature = (browser=None, http3=None, proxy=None, timeout=Some(Right(USE_CLIENT_DEFAULT_SENTINEL)), verify=None, default_encoding=None, follow_redirects=None, max_redirects=Some(20), cookie_jar=None, cookies=None, headers=None, local_address=None))]
40 pub fn new(
41 py: Python<'_>,
42 browser: Option<String>,
43 http3: Option<bool>,
44 proxy: Option<String>,
45 timeout: Option<Either<f64, &str>>,
46 verify: Option<bool>,
47 default_encoding: Option<String>,
48 follow_redirects: Option<bool>,
49 max_redirects: Option<u16>,
50 cookie_jar: Option<crate::Bound<'_, crate::PyAny>>,
51 cookies: Option<crate::Bound<'_, crate::PyAny>>,
52 headers: Option<HashMap<String, String>>,
53 local_address: Option<String>,
54 ) -> PyResult<Self> {
55 let builder = ImpitBuilder::default();
56
57 let builder = match browser {
58 Some(browser) => {
59 builder.with_fingerprint(crate::fingerprint::fingerprint_by_name(&browser)?)
60 }
61 None => builder,
62 };
63
64 let builder = match http3 {
65 Some(true) => builder.with_http3(),
66 _ => builder,
67 };
68
69 let builder = match proxy {
70 Some(proxy) => builder.with_proxy(proxy),
71 None => builder,
72 };
73
74 let builder = match parse_timeout(timeout)
75 .map_err(|e| ImpitPyError(ImpitError::BindingPassthroughError(e.to_string())))?
76 {
77 Some(Some(d)) => builder.with_default_timeout(d),
78 Some(None) => builder.with_default_timeout(Duration::MAX),
79 None => builder,
80 };
81
82 let builder = match verify {
83 Some(false) => builder.with_ignore_tls_errors(true),
84 _ => builder,
85 };
86
87 let builder = match follow_redirects {
88 Some(true) => builder.with_redirect(impit::impit::RedirectBehavior::FollowRedirect(
89 max_redirects.unwrap_or(20).into(),
90 )),
91 _ => builder.with_redirect(impit::impit::RedirectBehavior::ManualRedirect),
92 };
93
94 let builder = match headers {
95 Some(headers) => builder.with_headers(headers.into_iter().collect::<Vec<_>>()),
96 None => builder,
97 };

Callers

nothing calls this directly

Calls 13

fingerprint_by_nameFunction · 0.85
parse_timeoutFunction · 0.85
ImpitPyErrorClass · 0.85
with_proxyMethod · 0.80
with_default_timeoutMethod · 0.80
with_redirectMethod · 0.80
with_headersMethod · 0.80
with_cookie_storeMethod · 0.80
with_local_addressMethod · 0.80
with_fingerprintMethod · 0.45
with_http3Method · 0.45

Tested by

no test coverage detected