Skip to main content

File Scan | Python SDK

Initializes a new Pangea service client.

FileScan(token, config, logger_name)

str

Pangea API token.

PangeaConfig | None

Configuration.

str

Logger name.

Download file

FileScan.download_file(url, filename)

Download a file from the specified URL and save it with the given filename.

str

URL of the file to download

str | None

Name to save the downloaded file as. If not provided, the filename will be determined from the Content-Disposition header or the URL.

Scan

FileScan.file_scan(file_path, file, verbose, raw, provider, sync_call, transfer_method, source_url)

Scan a file for malicious content.

str

filepath to be opened and scanned

io.BufferedReader

file to be scanned (should be opened with read permissions and in binary format)

bool

Echo the API parameters in the response

bool

Include raw data from this provider

str

Scan file using this provider

bool

True to wait until server returns a result, False to return immediately and retrieve result asynchronously

TransferMethod

Transfer method used to upload the file data.

str

A URL where the Pangea APIs can fetch the contents of the input file.

A PangeaResponse where the sanctioned source(s) are in the response.result field. Available response fields can be found in our API Documentation.

try:
    with open("./path/to/file.pdf", "rb") as f:
        response = client.file_scan(file=f, verbose=True, provider="crowdstrike")
        print(f"Response: {response.result}")
except pe.PangeaAPIException as e:
    print(f"Request Error: {e.response.summary}")
    for err in e.errors:
        print(f"\t{err.detail} \n")

Poll result

FileScan.poll_result(exception)

Returns request's result that has been accepted by the server

Optional[AcceptedRequestException]

Exception that was previously raised by the SDK on a call that is being processed.

PangeaResponse

response = service.poll_result(exception)

request-upload-url

FileScan.request_upload_url()