mf2py icon indicating copy to clipboard operation
mf2py copied to clipboard

Feature request: make HTTP library pluggable

Open tommorris opened this issue 1 year ago • 2 comments

I was looking through the code for mf2py the other day and realised we boil requests in as a dependency. httpx exists and it's pretty good (async, http2, etc). Might be useful if we could make it support httpx as well as requests and reconsider requests as default. There are a few differences that are documented.

tommorris avatar Dec 04 '23 13:12 tommorris

Hello there,

Sorry to barge in, There's an alternative you may be interested in. https://github.com/jawah/niquests

This is a drop-in-worthy replacement for Requests that ships with modern capabilities and allows you a painless transition. I can answer any concerns you may have.

Ousret avatar Dec 06 '23 11:12 Ousret

The singular instance is here: https://github.com/microformats/mf2py/blob/8f72a81cb37934796939270116b7b7b7de888f88/mf2py/parser.py#L129-L143

requests' stability makes for a sensible default.

Here's what you'd currently have to use to leverage a different library:

import httpx
url = "https://example.com"
mf2py.parse(httpx.get(url), url=url)

Here's what we could do:

import httpx
mf2py.parse(url="https://example.com", url_fetcher=httpx)

This would work with anything that emulates the requests API -- specifically any namespace/object that has a .get() function/method:

import niquests
mf2py.parse(url="https://example.com", url_fetcher=niquests)

This would also enable session support which is something I've wanted before and may prove to be more useful as protected posts proliferate:

import requests
session = requests.Session()
session.auth = ('user', 'pass')
mf2py.parse(url="https://example.com", url_fetcher=session)

Choices for the keyword argument are url_fetcher, url_getter, user_agent, agent, ...

angelogladding avatar Dec 10 '23 22:12 angelogladding