Package: sfrout
SFrout - Sales Force Report DownloaderWhat is it?SFroutis a scalable, asynchronous SalesForce report downloader for SAML/SSO clients. The app allows you to download reports based on their ID using your personal SFDC account. Supports asynchronous requests, threaded processing of the files, logging to rotating file and stdout, produces summary report for the session.InstallationSFrout require Python 3.11 to work properly.navigate to some convenient folder (optional)cdc:/path/to/venvcreate Python virtual env (optional)python-mvenvc:/path/to/venvactivate virtual envfor Windows:c:\path\to\venv\Scripts\activate.batfor Unixsource/path/to/venv/bin/activateinstall sfrout from PyPipipinstallsfroutUsagePython interfacecreate a python file and paste in below script. Amend domain and path to your reports fileimportsfroutsfrout.run(domain="https://corp.my.salesforce.com/",reports_path="C:\\path\\to\\reports.csv")fill in reports.csv file according to given templateInput file templateexecute the script"c:/path/to/your/file.py"shortly after you might be prompted to log in to SalesForce in MS Edge, website will open automaticallynext the progress bar will show uponce finish,SFroutwill print summary tableCLIopen terminalcmd.exetype in commandsfrout"https://corp.my.salesforce.com/""C:\\path\\to\\reports.csv"fill in reports.csv file according to given templateInput file templateCLI interface allow you to configure parameters according to below list:Options:-s,--summary_filepathPATHPathtothesummaryreport->c:/summary_report.csv-r,--reportTEXTRunsinglereport->"name,id,path,optional_report_params"-p,--pathPATHOverridesavelocationofthereports-t,--threadsINTEGERNumberofthreadstospawn[default:0]-ls,--stdout_loglevelTEXTSTDOUTlogginglevel->[DEBUG|INFO|WARN|WARNING|ERROR|CRITICAL][default:WARNING]-lf,--file_loglevelTEXTFilelogginglevel->[DEBUG|INFO|WARN|WARNING|ERROR|CRITICAL][default:INFO]-v,--verboseTurnoffprogressbar-h,--helpShowthismessageandexit.Windows Task SchedulerCreatesfrout.bat, save it with below script:"c:\path\to\new\virtual\environment\Scripts\python.exe"sfrout"https://corp.my.salesforce.com/""C:\\path\\to\\reports.csv"pauseTest it, if works create a task and set some scheduleHow the program worksOnce you run the program:configuration, data parsingcreating connector, report, shared queue objectsinitialization of workers listeners within file handlerconnector will check the connection and execute all required steps to establish the connectionconnector will produce asynchronous requests to given domainonce single request is fulfilled retrieved content is being put into the queueworkers keep on listen for items in the queueonce queue is not empty some worker will take the item and start processingonce all the request are fulfilled queue will close and send signals to workers to shutdown once they finish their last jobSFDC ConnectorAuthentication:Authorization and authentication in SFDC is based onsidcookie entry for SSO or on security tokens in other cases.SFrout will try to connect to CookieJar of your MS Edge browser and findsidentry for given domain. Ifsidis not found, the app will open MS Edge and request given SFDC domain. You will be asked to log in as usual. After 20 seconds program will retry to findsidin your CookieJar. Browsers usually store cookies in SQlite db. This information is not being transfered to db immediately, it can be triggered by closing the browser but it isn't the most elegant solution. SFrout will ask forsidin 2 seconds intervals as long assidwill be available. Entire process will repeat as many times as it takes.Sending requests:SFDC supports export GET requests by adding?export=csv&enc=UTF-8&isdtp=p1to address of your supplemented with headers and abovesidentry. In response you will receive CSV-like data stream. Time window for entire operation is fixed and equal to15 minutes. If you will not be able to receive response in this narrow time window connection will be forceable shutdown and request cancelled regardless of the stage.Requests are send out asynchronously to speed things up and restrain memory consumption to bare minimum. Once request will fail, regardless of that what has caused failure, SFrout will retry. Limit of attempts has been set to20. Once request is successful, response is saved in Report object and put to the queue for further processing.File handlerThread based solution for saving request responses to a file.File handler spawns workers in separate threads. Number of workers is equal to half of available threads on your machine (e.g. if your cpu has 6 cores and 12 threads SFR will spawn 6 workers). If information about available resources is not reachable it will default to2. Such approach will not dramatically slow down other applications on your computer and will secure required resources for SFR. Each worker will observeQueue, if something will be put intoQueueone of the workers will start processing of the report. Bare in mind that each saving operation erases response and content of the report due to memory consumption.Queuesize is unlimited so sooner or later workers will handle entire workload. Workers will die onceQueuewill send signal that they shouldn't expect any new items. These workers who are just processing items will finish their jobs and die quietly.All files are processed byPandaswhich gives wide palette of available formats. Unfortunately such flexibility somes with the price. In current shapePandasisn't the best in savingcsvfiles due tonumpyengine. On top of thatPandasis a relatively heavy library. I plan to switch to some other processing engine in the future.LimitationsCaution!SFrout deletes last 5 lines from each response, SFDC adds footer to each data stream. This might be organization specific and require your attention if you plan to use it in your organization.be default number of workers is equal to half of available threads of the machineby default rotating file log is limitted to 3 parts, up to 1_000_000 bytes eachprogress bar is based on quantity of items and may show incorrect ETA if report's size vary significantlycurrently only save tocsvmethod is availableBenchmarksMy testing set consist of 33 reports from various universes of SFDC with size between 200 kb to 200 mb. In total 1.4 gb of data.Tests were not bounded by network bandwidth. Tests were evaluated on i7-8850H, DDR4 32 gb, Windows 10 x64.Processing of the testing set vary between 3 and 8 minutes, results strongly correlate to SFDC performance on given time. Time of processing is correlated to size of the reports, bigger = longer.Final remarksThis app has been created based on environment of my organization. There is alternative way of Authenticating to SFDC based on security token, unfortunately this option was blocked in my organization and only SSO is available.Documentation available onRead the DocsRelease NotesChangelogLicenseApache 2.0