
    i@                     &   d Z ddlmZmZmZmZmZ ddlZddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZ  ej        d	          Z G d
 d          Z G d d          Z G d d          Z G d d          Z G d d          Z G d d          ZeZeZdS )a  
Firecrawl Client

A Firecrawl client that enables you to scrape content from websites, crawl entire sites, search the web, and extract structured data using AI.

The client supports both v1 and v2 API versions, providing access to features like:
- Web scraping with advanced options (screenshots, markdown conversion, etc.)
- Site crawling with configurable depth and limits
- Web search with content extraction
- Structured data extraction using AI models
- Deep research capabilities

Usage:
    from firecrawl import Firecrawl
    firecrawl = Firecrawl(api_key="your-api-key")
    result = firecrawl.scrape("https://example.com")

Check example.py for other usage examples.
    )AnyDictOptionalListUnionN   )V1FirecrawlAppAsyncV1FirecrawlApp)FirecrawlClient)AsyncFirecrawlClient)Document	firecrawlc                   B    e Zd ZU dZee         ed<   dee         fdZdS )V1Proxy+Type-annotated proxy for v1 client methods._clientclient_instancec                    || _         |rz|j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j	        | _	        |j
        | _
        d S d S Nr   
scrape_url	crawl_urlbatch_scrape_urlsasync_batch_scrape_urlsasync_crawl_urlcheck_crawl_statusmap_urlextractdeep_researchgenerate_llms_textselfr   s     Z/home/agentuser/.hermes/hermes-agent/venv/lib/python3.11/site-packages/firecrawl/client.py__init__zV1Proxy.__init__$       & 
	I-8DO,6DN%4%FD"+:+RD(#2#BD &5&HD#*2DL*2DL!0!>D&5&HD###
	I 
	I    N)__name__
__module____qualname____doc__r   r	   __annotations__r$    r&   r#   r   r       sT         55n%%%%I(@ I I I I I Ir&   r   c                   H    e Zd ZU dZee         ed<   dee         fdZd ZdS )V2ProxyIProxy class that forwards method calls to the appropriate version client.r   r   c                    || _         |r|j        | _        |j        | _        |j        | _        |j        | _        | j        | _        | j        | _        |j        | _        |j        | _        |j	        | _	        |j
        | _
        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j         | _         |j!        | _!        |j"        | _"        |j#        | _#        |j$        | _$        |j%        | _%        |j&        | _&        |j'        | _'        d S d S r   )(r   scrapeinteractstop_interactionstop_interactive_browserscrape_executedelete_scrape_browsersearchcrawlstart_crawlget_crawl_statusget_crawl_status_pagecancel_crawlget_crawl_errorsget_active_crawlsactive_crawlscrawl_params_previewr   start_extractget_extract_statusagentstart_agentget_agent_statuscancel_agentstart_batch_scrapeget_batch_scrape_statusget_batch_scrape_status_pagecancel_batch_scrapebatch_scrapeget_batch_scrape_errorsmapget_concurrencyget_credit_usageget_token_usageget_queue_statusbrowserbrowser_executedelete_browserlist_browserswatcherr!   s     r#   r$   zV2Proxy.__init__7   s   & -	3)0DK+4DM$3$DD!,;,TD)"&-D)-)>D&)0DK(.DJ.:D$3$DD!)8)ND& / <D$3$DD!%4%FD"!0!>D(7(LD%*2DL!0!>D&5&HD#(.DJ.:D$3$DD! / <D&5&HD#+:+RD(0?0\D-'6'JD$ / <D+:+RD(&*DH#2#BD $3$DD!#2#BD $3$DD!*2DL#2#BD "1"@D!0!>D*2DLLL[-	3 -	3r&   c                 ,    t          | j        |          S )2Forward attribute access to the underlying client.)getattrr   r"   names     r#   __getattr__zV2Proxy.__getattr__i   s    t|T***r&   N)	r'   r(   r)   r*   r   V2FirecrawlClientr+   r$   r\   r,   r&   r#   r.   r.   3   s_         SS'((((031B(C 03 03 03 03d+ + + + +r&   r.   c                   B    e Zd ZU dZee         ed<   dee         fdZdS )AsyncV1Proxyr   r   r   c                    || _         |rz|j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j	        | _	        |j
        | _
        d S d S r   r   r!   s     r#   r$   zAsyncV1Proxy.__init__q   r%   r&   N)r'   r(   r)   r*   r   r
   r+   r$   r,   r&   r#   r_   r_   m   sV         55)****I1D(E I I I I I Ir&   r_   c                   N    e Zd ZU dZdZee         ed<   ddee         fdZd Z	dS )AsyncV2Proxyr/   Nr   r   c                    || _         |r|j        | _        |j        | _        |j        | _        |j        | _        | j        | _        | j        | _        |j        | _        |j        | _        |j	        | _	        |j
        | _
        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j         | _         |j!        | _!        |j"        | _"        |j#        | _#        |j$        | _$        |j%        | _%        |j&        | _&        |j'        | _'        |j(        | _(        |j)        | _)        d S d S r   )*r   r1   r2   r3   r4   r5   r6   r7   r8   r9   
wait_crawlr:   r;   r<   r=   r>   r?   r@   r   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   wait_batch_scraperK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   r!   s     r#   r$   zAsyncV2Proxy.__init__   s   & /	3)0DK+4DM$3$DD!,;,TD)"&-D)-)>D&)0DK(.DJ.:D-8DO$3$DD!)8)ND& / <D$3$DD!%4%FD"!0!>D(7(LD%*2DL!0!>D&5&HD#(.DJ.:D$3$DD! / <D&5&HD#+:+RD(0?0\D-'6'JD$%4%FD" / <D+:+RD(&*DH#2#BD $3$DD!#2#BD $3$DD!*2DL#2#BD "1"@D!0!>D*2DLLL_/	3 /	3r&   c                 ^    | j         rt          | j         |          S t          d|           )rX   z%Async v2 client not implemented yet: )r   rY   AttributeErrorrZ   s     r#   r\   zAsyncV2Proxy.__getattr__   s5    < 	/4<...KTKKLLLr&   r   )
r'   r(   r)   r*   r   r   r   r+   r$   r\   r,   r&   r#   rb   rb      sm         SS.2GX*+22223 231E(F 23 23 23 23hM M M M Mr&   rb   c                   :    e Zd ZdZ	 	 	 	 	 ddededed	ed
ef
dZdS )	Firecrawlz
    Unified Firecrawl client (v2 by default, v1 under ``.v1``).

    Provides a single entrypoint that exposes the latest API directly while
    keeping a feature-frozen v1 available for incremental migration.
    Nhttps://api.firecrawl.dev         ?api_keyapi_urltimeoutmax_retriesbackoff_factorc                 4   || _         || _        t          rt          ||          nd| _        t          rt	          |||||          nd| _        | j        rt          | j                  nd| _        t          | j                  | _	        | j        j
        | _
        | j        j        | _        | j        j        | _        | j        j        | _        | j        | _        | j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j         | _         | j        j!        | _!        | j        j"        | _"        | j        j#        | _#        | j        j$        | _$        | j        j%        | _%        | j        j&        | _&        | j        j'        | _'        | j        j(        | _(        | j        j)        | _)        | j        j*        | _*        | j        j+        | _+        | j        j,        | _,        | j        j-        | _-        | j        j.        | _.        | j        j/        | _/        | j        j0        | _0        dS )a  Initialize the unified client.

        Args:
            api_key: Firecrawl API key (or set ``FIRECRAWL_API_KEY``)
            api_url: Base API URL (defaults to production)
            timeout: Default request timeout in seconds for all HTTP requests
            max_retries: Maximum number of retries for failed requests (default: 3)
            backoff_factor: Exponential backoff factor for retries (default: 0.5)
        rm   rn   Nrm   rn   ro   rp   rq   )1rm   rn   r	   
_v1_clientr]   
_v2_clientr   v1r.   v2r1   r2   r3   r4   r5   r6   r7   rM   r8   r9   r@   r:   r;   r<   r=   r>   r?   rG   rH   rI   rJ   rK   rL   rA   rB   r   rD   rE   rF   rC   rN   rO   rP   rQ   rR   rS   rT   rU   rV   r"   rm   rn   ro   rp   rq   s         r#   r$   zFirecrawl.__init__   s   "  O]f.'JJJJbf )+#)
 
 
 
 %) 	 /3oG'$/***4$/**o,0 $ @(,(P%"m%)%:"o,?&_*
?6$(O$H! $ @%)_%J" O8 $ @!%!B!_:"&/"D'+'N$,0O,X)#'?#F  O8'+'N$!_:"&/"D.?6 $ @ O8_*
#> $ @#> $ @.#>"o<!_:.r&   Nrj   Nrk   rl   r'   r(   r)   r*   strfloatintr$   r,   r&   r#   ri   ri      s          2 #O/ O/O/ O/ 	O/
 O/ O/ O/ O/ O/ O/ O/r&   ri   c                   :    e Zd ZdZ	 	 	 	 	 ddededed	ed
ef
dZdS )AsyncFirecrawlzAAsync unified Firecrawl client (v2 by default, v1 under ``.v1``).Nrj   rk   rl   rm   rn   ro   rp   rq   c                    || _         || _        t          rt          ||          nd | _        t          rt	          |||||          nd | _        | j        rt          | j                  nd | _        t          | j                  | _	        | j        j
        | _
        | j        j        | _        | j        j        | _        | j        j        | _        | j        | _        | j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j         | _         | j        j!        | _!        | j        j"        | _"        | j        j#        | _#        | j        j$        | _$        | j        j%        | _%        | j        j&        | _&        | j        j'        | _'        | j        j(        | _(        | j        j)        | _)        | j        j*        | _*        | j        j+        | _+        | j        j,        | _,        | j        j-        | _-        | j        j.        | _.        | j        j/        | _/        d S )Nrs   rt   )0rm   rn   r
   ru   r   rv   r_   rw   rb   rx   r1   r2   r3   r4   r5   r6   r7   rM   r9   r:   r;   r<   r8   r=   r?   r@   rG   rH   rI   rJ   rK   rL   rA   rB   r   rD   rE   rF   rC   rN   rO   rP   rQ   rR   rS   rT   rU   rV   ry   s         r#   r$   zAsyncFirecrawl.__init__  s     Tgp-gwOOOOlp ",.#)
 
 
 
 (, 	 48?L,t///t// o,0 $ @(,(P%"m%)%:"o,?&?6 $ @%)_%J" O8_*
 $ @!_:$(O$H!"&/"D'+'N$,0O,X)#'?#F  O8'+'N$!_:"&/"D.?6 $ @ O8_*
#> $ @#> $ @.#>"o<!_:.r&   rz   r{   r,   r&   r#   r   r     s        KK 2 #G/ G/G/ G/ 	G/
 G/ G/ G/ G/ G/ G/ G/r&   r   )r*   typingr   r   r   r   r   loggingrw   r	   r
   rx   r   r]   v2.client_asyncr   v2.typesr   	getLoggerloggerr   r.   r_   rb   ri   r   FirecrawlAppAsyncFirecrawlAppr,   r&   r#   <module>r      s   ( 4 3 3 3 3 3 3 3 3 3 3 3 3 3  4 3 3 3 3 3 3 3 4 4 4 4 4 4 1 1 1 1 1 1      		;	'	'I I I I I I I I&8+ 8+ 8+ 8+ 8+ 8+ 8+ 8+tI I I I I I I I&<M <M <M <M <M <M <M <M~W/ W/ W/ W/ W/ W/ W/ W/rJ/ J/ J/ J/ J/ J/ J/ J/Z "   r&   