Skip to content

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)

Co-authored-by: Christoph Wegener <cwegener@users.noreply.github.com>
Co-authored-by: HLFH <github@dhautefeuille.eu>
Smart123s and others added 2 commits October 31, 2025 20:52
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>
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.

1 participant