Python module ipfshttpclient deprecated, any newer option to add file or directory?

Hi there,

While trying to find a simple solution to upload a whole directory to local ipfs daemon using ipfs-http-client 0.7.0 python module:

import ipfshttpclient
def ipfs_add(content_path):
  client = ipfshttpclient.connect('/ip4/127.0.0.1/tcp/5001')
  res = client.add(content_path, recursive=True)
  print(res)

I get an incompatibility error between api for python module and kubo api number;

 File "/Users/kalou/dev/py/qtbittorrent/./get-torrents-seeding-hashes.py", line 37, in ipfs_add
    client = ipfshttpclient.connect('/ip4/127.0.0.1/tcp/5001')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kalou/dev/py/qtbittorrent/venv/lib/python3.12/site-packages/ipfshttpclient/client/__init__.py", line 119, in connect
    assert_version(client.apply_workarounds()["Version"])
  File "/Users/kalou/dev/py/qtbittorrent/venv/lib/python3.12/site-packages/ipfshttpclient/client/__init__.py", line 69, in assert_version
    raise exceptions.VersionMismatch(version, minimum, maximum)
ipfshttpclient.exceptions.VersionMismatch: Unsupported daemon version '0.28.0' (not in range: 0.4.23 ≤ … < 0.8.0)

Is there any newer solution available for python ?
May I better fork an ipfs add process using “os python module” ?

I ended up using python “subprocess” module to call the external ipfs binary (kubo).

Here are two examples:

# get the cid for a file or directory 

def get_ipfs_cid(hash, size, content_path):

  cmd='ipfs add -r --only-hash --quiet ' + '''"''' + content_path + '''"'''
  try:
    cmd_out = subprocess.check_output(cmd, shell=True)
  except:
    print("ipfs add failed for " + content_path)
    sys.exit()

  hash_str = cmd_out.decode()
  l = hash_str.split()       # get rid of trailing newline
  if l[-1] == '':
    l.pop()

  return l
# test if local ipfs server is running

def ipfs_check():

    url='http://127.0.0.1:5001/webui/api/v0/version'
    try:
        r = requests.get(url)
    except:
        print("IPFS server not running")
        sys.exit()

    if r.status_code != 200:
        print("IPFS server not running")
        sys.exit()