### Get Request Example Source: https://github.com/gufolabs/gufo_http/blob/master/docs/examples/sync/get.md This is the main example demonstrating a synchronous GET request. It shows how to import `HttpClient`, define a main function, create an `HttpClient` instance, make a GET request to a specified URL, check the response status code, and print the decoded response content. ```Python import sys from gufo.http.sync_client import HttpClient def main(): url = sys.argv[1] with HttpClient() as client: response = client.get(url) if response.status_code != 200: print(f"Error: Received status code {response.status_code}") return content = response.content.decode('utf-8') print(content) if __name__ == '__main__': main() ``` -------------------------------- ### Install Local Nginx Source: https://github.com/gufolabs/gufo_http/blob/master/docs/benchmarks.md Installs a local Nginx server using the provided setup script. ```bash ./tools/build/setup-nginx.sh ``` -------------------------------- ### Install Benchmarking Dependencies Source: https://github.com/gufolabs/gufo_http/blob/master/docs/benchmarks.md Installs third-party packages required for benchmarking. ```bash ./tools/build/setup-bench.sh ``` -------------------------------- ### Install Gufo HTTP Source: https://github.com/gufolabs/gufo_http/blob/master/docs/installation.md Use this command to install the Gufo HTTP library via pip. ```bash $ pip install gufo_http ``` -------------------------------- ### Async Get Request Example Source: https://github.com/gufolabs/gufo_http/blob/master/docs/examples/async/get.md This is the main asynchronous GET request function. It handles fetching content from a given URL. ```python --8<-- "examples/async/get.py" ``` -------------------------------- ### Install Test Dependencies Source: https://github.com/gufolabs/gufo_http/blob/master/docs/benchmarks.md Installs the project's test dependencies and the gufo-http package in editable mode. ```bash pip3 install -e .[test] gufo-http ``` -------------------------------- ### Check Gufo HTTP Installation Source: https://github.com/gufolabs/gufo_http/blob/master/docs/installation.md Import the module to verify that Gufo HTTP has been installed correctly. ```python from gufo.http import __version__ ``` -------------------------------- ### Prepare Debian 12 Node Source: https://github.com/gufolabs/gufo_http/blob/master/docs/benchmarks.md Installs git and Python 3.11 with venv, then sets up a virtual environment for benchmarking. ```bash sudo apt-get update sudo apt-get install --yes git python3.11-venv python3 -m venv bench cd bench . bin/activate ``` -------------------------------- ### Basic GET Request Source: https://github.com/gufolabs/gufo_http/blob/master/README.md Demonstrates how to perform a basic GET request to a URL using the HttpClient in asynchronous mode. Ensure HttpClient is imported. ```python async with HttpClient() as client: resp = client.get("https://docs.gufolabs.com/") assert resp.status == 200 data = resp.content ``` -------------------------------- ### Rebuild Rust Modules and Install Package Source: https://github.com/gufolabs/gufo_http/blob/master/docs/dev/testing.md Installs the package in editable mode, which is necessary for rebuilding Rust modules and for development. ```shell python -m pip install --editable . ``` -------------------------------- ### Run Benchmark Tests Source: https://github.com/gufolabs/gufo_http/blob/master/docs/benchmarks.md Execute the benchmark tests using pytest. Ensure you have pytest and the benchmark plugin installed. ```bash pytest benchmarks/test_https_p4_x100_1k.py ``` -------------------------------- ### Run Benchmark Tests Source: https://github.com/gufolabs/gufo_http/blob/master/docs/benchmarks.md Execute the benchmark tests using pytest. Ensure you have pytest and the benchmark plugin installed. ```bash pytest benchmarks/test_p4_x100_1k.py ``` -------------------------------- ### Upgrade Gufo HTTP Source: https://github.com/gufolabs/gufo_http/blob/master/docs/installation.md Run this command to upgrade an existing Gufo HTTP installation to the latest version. ```bash $ pip install --upgrade gufo_http ``` -------------------------------- ### GET Request with Custom Headers Source: https://github.com/gufolabs/gufo_http/blob/master/README.md Shows how to set custom request headers for an HTTP request. The headers are provided as a dictionary. ```python async with HttpClient(headers={"X-My-Header": b"test"}) as client: resp = client.get("https://docs.gufolabs.com/") ... ``` -------------------------------- ### Build and Serve Documentation Source: https://github.com/gufolabs/gufo_http/blob/master/docs/dev/testing.md Rebuilds and serves the project's documentation locally. This command is used to preview documentation changes. ```shell mkdocs serve ``` -------------------------------- ### HTTP Request with Basic Authentication Source: https://github.com/gufolabs/gufo_http/blob/master/README.md Demonstrates how to use Basic Authentication for an HTTP request. Requires importing BasicAuth. ```python async with HttpClient(auth=BasicAuth("scott", "tiger")) as client: resp = client.get("https://protected.example.com/") ... ``` -------------------------------- ### Build Package Source: https://github.com/gufolabs/gufo_http/blob/master/docs/dev/testing.md Builds the package into source distribution and wheel formats. Compiled packages are placed in the 'dist/' directory. ```shell python -m build --sdist --wheel ``` -------------------------------- ### Run Linear Requests Benchmark Source: https://github.com/gufolabs/gufo_http/blob/master/docs/benchmarks.md Execute the benchmark test suite for linear requests. This command initiates the performance tests. ```bash pytest benchmarks/test_linear_x100_1k.py ``` -------------------------------- ### Run HTTP Benchmarks Source: https://github.com/gufolabs/gufo_http/blob/master/docs/benchmarks.md Execute the pytest suite for single HTTP requests to read a 1kb text file. This command initiates tests evaluating client initialization, network efficiency, resolver performance, and HTTP/1.1 parsing. ```bash pytest benchmarks/test_single_x100_1k.py ``` -------------------------------- ### Run Test Suite Source: https://github.com/gufolabs/gufo_http/blob/master/docs/dev/testing.md Executes the project's test suite using pytest. This command should be run after ensuring Rust modules are rebuilt if necessary. ```shell pytest -vv ``` -------------------------------- ### Benchmark Results Summary Source: https://github.com/gufolabs/gufo_http/blob/master/docs/benchmarks.md A summary of benchmark results for linear HTTPS requests, showing performance metrics for various libraries. Lower values indicate better performance. ```text ================================================================= test session starts ================================================================= platform linux -- Python 3.11.2, pytest-7.4.3, pluggy-1.4.0 benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000) rootdir: /home/admin/bench/gufo_http plugins: anyio-4.3.0, benchmark-4.0.0 collected 11 items benchmarks/test_https_linear_x100_1k.py ........... [100%] ---------------------------------------------------------------------------------------- benchmark: 11 tests ----------------------------------------------------------------------------------------- Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ test_pycurl_sync 23.7046 (1.0) 34.5084 (1.0) 28.0373 (1.0) 2.7286 (1.05) 27.5175 (1.0) 3.1725 (1.51) 13;1 35.6668 (1.0) 36 1 test_gufo_http_sync 29.9783 (1.26) 43.9089 (1.27) 34.6652 (1.24) 3.4124 (1.31) 34.1431 (1.24) 3.3721 (1.60) 6;2 28.8473 (0.81) 27 1 test_gufo_http_async 46.8830 (1.98) 60.8049 (1.76) 52.9559 (1.89) 3.4813 (1.34) 53.4698 (1.94) 3.3365 (1.59) 6;1 18.8836 (0.53) 20 1 test_aiohttp_async 54.6583 (2.31) 67.3119 (1.95) 59.1695 (2.11) 3.4653 (1.33) 58.1128 (2.11) 3.0986 (1.47) 3;1 16.9006 (0.47) 12 1 test_httpx_sync 81.5782 (3.44) 92.6393 (2.68) 86.0377 (3.07) 2.6015 (1.0) 85.8659 (3.12) 2.1049 (1.0) 2;2 11.6228 (0.33) 12 1 test_aiosonic_async 83.6425 (3.53) 92.7221 (2.69) 88.8669 (3.17) 3.0862 (1.19) 88.5831 (3.22) 4.7266 (2.25) 4;0 11.2528 (0.32) 11 1 test_urllib3_sync 93.8056 (3.96) 108.2151 (3.14) 103.6100 (3.70) 4.4636 (1.72) 104.2995 (3.79) 5.2626 (2.50) 3;1 9.6516 (0.27) 10 1 test_httpx_async 121.2678 (5.12) 129.0288 (3.74) 125.5163 (4.48) 2.7471 (1.06) 125.2434 (4.55) 4.4465 (2.11) 3;0 7.9671 (0.22) 8 1 test_niquests_sync 139.6578 (5.89) 149.3103 (4.33) 145.1738 (5.18) 3.3405 (1.28) 145.8421 (5.30) 3.7032 (1.76) 2;0 6.8883 (0.19) 6 1 test_urllib_sync 1,128.9319 (47.63) 1,143.7361 (33.14) 1,138.7279 (40.61) 5.9014 (2.27) 1,140.5120 (41.45) 7.1488 (3.40) 1;0 0.8782 (0.02) 5 1 test_requests_sync 4,121.8836 (173.89) 4,151.7480 (120.31) 4,131.9819 (147.37) 11.9202 (4.58) 4,129.1534 (150.06) 14.5257 (6.90) 1;0 0.2420 (0.01) 5 1 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Legend: Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile. OPS: Operations Per Second, computed as 1 / Mean ==================================================== 11 passed, 1215 warnings in 62.84s (0:01:02) ===================================================== ``` -------------------------------- ### Run Linear HTTPS Request Benchmark Source: https://github.com/gufolabs/gufo_http/blob/master/docs/benchmarks.md Execute the benchmark test for 100 linear HTTPS requests to a 1kb text file. This command uses pytest to run the specified test file. ```bash pytest benchmarks/test_https_linear_x100_1k.py ``` -------------------------------- ### Clone Gufo HTTP Repository Source: https://github.com/gufolabs/gufo_http/blob/master/docs/benchmarks.md Clones the Gufo HTTP project from GitHub and navigates into the project directory. ```bash git clone https://github.com/gufolabs/gufo_http.git cd gufo_http ``` -------------------------------- ### Check Code Formatting Source: https://github.com/gufolabs/gufo_http/blob/master/docs/dev/testing.md Checks the code formatting across specified directories using Ruff. This is a mandatory requirement for code quality. ```shell ruff format --check examples/ src/ tests/ ``` -------------------------------- ### Processing Response Headers Source: https://github.com/gufolabs/gufo_http/blob/master/README.md Illustrates how to access and check response headers. Headers can be accessed like a dictionary. ```python async with HttpClient(headers={"X-My-Header": b"test"}) as client: resp = client.get("https://docs.gufolabs.com/") if resp.headers["Content-Type"] == "text/html": ... ``` -------------------------------- ### Generate HTML Coverage Report Source: https://github.com/gufolabs/gufo_http/blob/master/docs/dev/testing.md Generates an HTML report detailing line-by-line code coverage. The report can be viewed by opening 'dist/coverage/index.html' in a browser. ```shell coverage html ``` -------------------------------- ### Run HTTPS Single Request Benchmarks Source: https://github.com/gufolabs/gufo_http/blob/master/docs/benchmarks.md Execute the pytest command to run the benchmarks for single HTTPS requests. This command initiates a series of tests to measure performance. ```bash pytest benchmarks/test_https_single_x100_1k.py ``` -------------------------------- ### Run Tests for Coverage Source: https://github.com/gufolabs/gufo_http/blob/master/docs/dev/testing.md Runs the test suite using pytest while collecting code coverage data. This is the first step to evaluating code coverage. ```shell coverage run -m pytest -vv ``` -------------------------------- ### Generate Coverage Report Source: https://github.com/gufolabs/gufo_http/blob/master/docs/dev/testing.md Generates a text-based report of the code coverage after tests have been run with coverage enabled. It shows which lines were executed. ```shell coverage report ``` -------------------------------- ### Uninstall Gufo HTTP Source: https://github.com/gufolabs/gufo_http/blob/master/docs/installation.md Use this command to remove the Gufo HTTP library from your system. ```bash $ pip uninstall gufo_http ``` -------------------------------- ### Check Python Code Lints Source: https://github.com/gufolabs/gufo_http/blob/master/docs/dev/testing.md Checks the Python code for linting errors using Ruff. This is a mandatory requirement for code quality. ```shell ruff src/ tests/ ``` -------------------------------- ### Fix Code Formatting Source: https://github.com/gufolabs/gufo_http/blob/master/docs/dev/testing.md Automatically fixes code formatting errors in the specified directories using Ruff. It is recommended to enable this on file save. ```shell ruff format examples/ src/ tests/ ``` -------------------------------- ### Check Python Code Static Typing Source: https://github.com/gufolabs/gufo_http/blob/master/docs/dev/testing.md Performs static type checking on the Python code using MyPy. This helps catch type-related errors before runtime. ```shell mypy src/ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.