X Tutup
Skip to content

Transform Flaresolverr into a python (pip) package#1603

Open
Smart123s wants to merge 4 commits intoFlareSolverr:masterfrom
Smart123s:feat/pip-package
Open

Transform Flaresolverr into a python (pip) package#1603
Smart123s wants to merge 4 commits intoFlareSolverr:masterfrom
Smart123s:feat/pip-package

Conversation

@Smart123s
Copy link

@Smart123s Smart123s commented Oct 30, 2025

This PR consists of 2 commits (for now). The first one is mostly an updated version of the 3 years old #651 pull request.
The second commit exports some basic functions, so they can be called directly from the python package, without having to start a HTTP web server.

  1. Uses Hatch for packiging.
  2. Renamed src directory to flaresolverr
  3. Moved imports so they can be used by packages.
  4. Added an __init__ file to export functionality for other python libraries.
  5. Extracted the web server start logic from main so simply importing the package won't start the web server (starting the CLI still starts the web server)
  6. Added a flaresolverr.py starter script to the root of the git repository
  7. Use flaresolverr logger (imported from V3beta - Python improvements #567). This makes it possible for packages to hide flaresolverr logs

The changes make it possible to install FlareSolverr as a python package, and solve a challenge directly using python code, without having to start a web server. For example:

pip install git+https://github.com/Smart123s/FlareSolverr.git@feat/pip-package
import flaresolverr
import logging

# Set up FlareSolverr logging
logging.getLogger("flaresolverr").setLevel(logging.ERROR)
flaresolverr_logger = logging.getLogger("flaresolverr")
flaresolverr_logger.setLevel(logging.ERROR)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(flaresolverr_log_level)
flaresolverr_logger.addHandler(ch)

# Initialize FlareSolverr (should be run once)
flaresolverr.init()

# Send a request (solve a captcha)
data = flaresolverr.V1RequestBase({
  "url": "http://www.google.com/",
  "maxTimeout": 60000
})
solution = flaresolverr.resolve_challenge(data, "GET")

print(solution.result.response)
print(solution.result.cookies)

I didn't want to change too much of the original code, so most of the functions exposed by the package are the functions currently used by Flaresolverr. In the future, a proper, package oriented API design should be considered, but I think that's out of scope for this PR for now.

Tested the build process and Cloudflare challange solving on

  • Windows Standalone executable
  • Docker
  • Running from source (python flaresolverr.py)

Smart123s and others added 3 commits October 29, 2025 10:43
Co-authored-by: Christoph Wegener <cwegener@users.noreply.github.com>
Co-authored-by: HLFH <github@dhautefeuille.eu>
Move web server startup to separate function

This makes it possible to call FlareSolverr functions directly from python code without having to start up a webserver.
added custom flaresolverr logger, avoiding to have to disable other loggers

cli logging setup (eg format, log level) is only run when script is actually started from the cli

Co-authored-by: M4RC0Sx <marcos3as3@gmail.com>
@Smart123s Smart123s force-pushed the feat/pip-package branch 2 times, most recently from 229059b to a96bc2a Compare October 31, 2025 19:52
@flowerey
Copy link
Contributor

@ilike2burnthing any updates on this? This would be pretty good to be honest.

@Smart123s
Copy link
Author

Rebased the branch on master to resolve a simple merge conflict with the readme file.

@Smart123s Smart123s reopened this Nov 15, 2025
@ilike2burnthing
Copy link
Contributor

This is a substantial change which will not be done by me, I'd need the owner to take a look when they have time.

Please don't ping for updates, it's a waste of everyone's time. If there were updates on a PR or issue, you'd see a comment to that effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

X Tutup