Code Monkey home page Code Monkey logo

request-boost's Introduction

request-boost

Go to https://pypi.org/project/request-boost/

A better requests and urllib package.
A simple package for hitting multiple URLs and performing GET/POST requests in parallel.
Go to https://pypi.org/project/request-boost/ Go to https://pypi.org/project/request-boost/ Go to https://pypi.org/project/request-boost/ Go to https://pypi.org/project/request-boost/

Setup

pip install request-boost

Important: Virtual Environment is recommended

Usage

# Sample data
number_of_sample_urls = 1000
urls = [ f'https://postman-echo.com/get?random_data={test_no}' for test_no in range(number_of_sample_urls) ]
headers = [{'sample_header':test_no} for test_no in range(number_of_sample_urls)]
from request_boost import boosted_requests

results = boosted_requests(urls=urls)
print(results)
from request_boost import boosted_requests

results = boosted_requests(urls=urls, no_workers=16, max_tries=5, timeout=5, headers=headers, verbose=True, parse_json=True)
print(results)
from request_boost import boosted_requests

# Config
number_of_sample_urls = 100

# Sample data
urls = [f'https://postman-echo.com/get?random_data={test_no}' for test_no in range(number_of_sample_urls)]
post_urls = [f'https://postman-echo.com/post' for test_no in range(number_of_sample_urls)]
headers = [{'sample_header': test_no} for test_no in range(number_of_sample_urls)]
data = [{'sample_data': test_no} for test_no in range(number_of_sample_urls)] # Required for POST requests, 
#For POST request data can be just list of empty dict but not NONE

simple_results = boosted_requests(urls=urls, no_workers=16, max_tries=5, timeout=5, headers=None, verbose=False, parse_json=True)
header_results = boosted_requests(urls=urls, no_workers=16, max_tries=5, timeout=5, headers=headers, parse_json=True)
post_results = boosted_requests(urls=post_urls, no_workers=16, max_tries=5, timeout=5, headers=headers, data=data, verbose=True, parse_json=True)

Documentation

Go to https://github.com/singhsidhukuldeep/request-boost/raw/main/img/structure.jpg

boosted_requests(
    urls,
    no_workers=32,
    max_tries=5,
    after_max_tries="assert",
    timeout=10,
    headers=None,
    data=None,
    verbose=True,
    parse_json=True,
)

Get data from APIs in parallel by creating workers that process in the background
    :param urls: list of URLS
    :param no_workers: maximum number of parallel processes {Default::32}
    :param max_tries: Maximum number of tries before failing for a specific URL {Default::5}
    :param after_max_tries: What to do if not successfull after "max_tries" for a specific URL, 
                            one of {"assert", "break"} {Default::assert}
    :param timeout: Waiting time per request {Default::10}
    :param headers: Headers if any for the URL requests
    :param data: data if any for the URL requests (Wherever not None a POST request is made)
    :param verbose: Show progress [True or False] {Default::True}
    :param parse_json: Parse response to json [True or False] {Default::True}
    :return: List of response for each API (order is maintained)

🌟⭐✨STAR ME✨⭐🌟

You can give me a small 🤓 dopmaine 🤝 support by ⭐STARRING⭐ this project 🌟⭐✨STAR ME✨⭐🌟

Credits

Maintained by

Kuldeep Singh Sidhu

Github: github/singhsidhukuldeep https://github.com/singhsidhukuldeep

Website: Kuldeep Singh Sidhu (Website) http://kuldeepsinghsidhu.com

LinkedIn: Kuldeep Singh Sidhu (LinkedIn) https://www.linkedin.com/in/singhsidhukuldeep/

Contributors

The full list of all the contributors is available here

https://github.com/singhsidhukuldeep

TODO:: Want to contribute?

  • Make the backend used (urllib/request library) an option that the user can choose, by default we use urllib
  • For parallel processing add options for multi-processing along with multi-threading
  • Set-up tests for edge cases and changes verification
  • Set-up CI/CD pipleine (possibly using GitHub actions) to publish changes to PyPi
  • Improeve the doc-strings documentation to add more explanantion and examples
  • Add a message queue to deploy the service across machines
  • Add option to run URL requests with Self signed certificate verify=False
  • Add option to supress warnings
  • Add progess bars from tqdm and ascii
  • Add option to add session and auth

Say Thanks

If this helped you in any way, it would be great if you could share it with others.

Steps for publishing to pypi [This is just for me, Maybe!]

  • pip3 install setuptools twine
  • Go to project folder
  • python3 setup.py sdist
  • twine upload --repository-url https://upload.pypi.org/legacy/ dist/*

OR

Go to your project folder and:

pip3 install setuptools twine

python3 setup.py sdist
twine upload --repository-url https://upload.pypi.org/legacy/ dist/*

Current Status

Issues Contributors Forks Stars Watchers Branches

License: AGPL v3 made-with-python repo- size Followers

request-boost's People

Contributors

giubaru avatar lgtm-migrator avatar singhsidhukuldeep avatar talhajunaidd avatar the-cob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

request-boost's Issues

Is this working also in YT, if yes, it's not working...

not working on me... can you pls help

C:\Python36\request-boost-main>setup.py
Traceback (most recent call last):
File "C:\Python36\request-boost-main\setup.py", line 11, in
from setuptools import setup, find_packages
ImportError: No module named setuptools

UnicodeError utf-8

self.results[loc] = json.loads(response.read())

Please consider adding the code below to fix the encoding when an utf8 api is consumed:

data = response.read()
encoding = response.info().get_content_charset("utf-8")
self.results[loc] = json.loads(data.decode(encoding))

Can boosted requests inherit a session's authentication?

Was somewhat inspired by this SO question but I'm wondering if it's possible for the boosted requests to inherit any properties from something like a requests session? Specifically the authentication piece which is very helpful.

https://stackoverflow.com/questions/44020439/session-auth-in-python

with requests.sessions.Session() as session:
    session.auth = ("username", "password")
    
    # Make any requests here without provide auth info again
    session.get("http://www.example.com/users")

My use case is an authenticated api that doesn't have a bulk endpoint 🤦‍♂️🤦‍♂️
Consequently, I have to send something like the following request on loop:
session.get("http://www.example.com/users/<userid>")

Right now, my only option is attempting to "impersonate" my Postman / Insomnia authorization by copying the hashed Authorization directly into a static key on the header.

Something like:
headers = [{'API_KEY': 'my_key', 'Authorization': 'Basic asdfjl1234567890='} for user_id in range(len(all_user_ids))]

any way to turn off exception messages?

url_ske = "https://api.dictionaryapi.dev/api/v2/entries/en/{}" urls = [url_ske.format(lemma) for lemma in ["bugler","hello","scaper"]] results = boosted_requests(urls=urls, max_tries=1)
the code above results in "AssertionError: Maximum number of attempts reached 1"
i think the reason is that free dictionary api returns a 404 response object whenever it fails to find any def for a word.
i could just turn off verbose but that turns off progress as well :(
please fix thanks.

Update on pypi

Hi singhsidhukuldeep,

Thanks a lot for the library, it has been really helpful for a tool I've created!
I am encountering a KeyError when reaching the timeout on some requests, and I see it has been fixed by this commit: d78edf4

However the library hasn't been updated on pypi.org since more than a year.
I think it would be really convenient to have a new version containing this patch. Would you be able to build/upload one if you have some time please?

Have a nice day!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.