<commit_before>IPFS API Bindings for Python
============================

Check out `ipfs <http://ipfs.io/>`_ and `the api command reference <http://ipfs.io/docs/commands/>`_ for more information about the IPFS Api.

Install with pip:

.. code-block::

    pip install ipfs-api

Basic use-case (requires a running instance of IPFS daemon):

.. code-block:: python

    >>> import ipfsApi
    >>> api = ipfsApi.Client('127.0.0.1', 5001)
    >>> res = api.add('test.txt')
    >>> res
    {'Hash': 'QmWxS5aNTFEc9XbMX1ASvLET1zrqEaTssqt33rVZQCQb22', 'Name': 'test.txt'}
    >>> api.cat(res['Hash'])
    'fdsafkljdskafjaksdjf\n'

Administrative functions:

.. code-block:: python

    >>> api.id()
    {'Addresses': ['/ip4/127.0.0.1/tcp/4001/ipfs/QmS2C4MjZsv2iP1UDMMLCYqJ4WeJw8n3vXx1VKxW1UbqHS',
                   '/ip6/::1/tcp/4001/ipfs/QmS2C4MjZsv2iP1UDMMLCYqJ4WeJw8n3vXx1VKxW1UbqHS'],
     'AgentVersion': 'go-ipfs/0.3.8-dev',
     'ID': 'QmS2C4MjZsv2iP1UDMMLCYqJ4WeJw8n3vXx1VKxW1UbqHS',
     'ProtocolVersion': 'ipfs/0.1.0',
     'PublicKey': '<KEY>}

Pass in API options:

.. code-block:: python

    >>> api.pin_ls(opts={'type':'all'})
    {'Keys': {'<KEY>U': {'Count': 1,
                                                                 'Type': 'indirect'},
              'QmNQ1h6o1xJARvYzwmySPsuv9L5XfzS4WTvJSTAWwYRSd8': {'Count': 1,
                                                                 'Type': 'indirect'},
              ...

Add a directory and match against a filename pattern:

.. code-block:: python

    >>> api.add('photos', match='*.jpg')
    [{'Hash': 'QmcqBstfu5AWpXUqbucwimmWdJbu89qqYmE3WXVktvaXhX',
      'Name': 'photos/photo1.jpg'},
     {'Hash': 'QmSbmgg7kYwkSNzGLvWELnw1KthvTAMszN5TNg3XQ799Fu',
      'Name': 'photos/photo2.jpg'},
     {'Hash': 'Qma6K85PJ8dN3qWjxgsDNaMjWjTNy8ygUWXH2kfoq9bVxH',
      'Name': 'photos/photo3.jpg'}]

Or add a directory recursively:

.. code-block:: python

    >>> api = ipfsApi.Client()
    >>> api.add('fake_dir', recursive=True)<commit_msg>minor readme<commit_after>IPFS API Bindings for Python
============================

Check out `ipfs <http://ipfs.io/>`_ and `the api command reference <http://ipfs.io/docs/commands/>`_ for more information about the IPFS Api.

Install with pip:

.. code-block::

    pip install ipfs-api

Basic use-case (requires a running instance of IPFS daemon):

.. code-block:: python

    >>> import ipfsApi
    >>> api = ipfsApi.Client('127.0.0.1', 5001)
    >>> res = api.add('test.txt')
    >>> res
    {'Hash': 'QmWxS5aNTFEc9XbMX1ASvLET1zrqEaTssqt33rVZQCQb22', 'Name': 'test.txt'}
    >>> api.cat(res['Hash'])
    'fdsafkljdskafjaksdjf\n'

Administrative functions:

.. code-block:: python

    >>> api.id()
    {'Addresses': ['/ip4/127.0.0.1/tcp/4001/ipfs/QmS2C4MjZsv2iP1UDMMLCYqJ4WeJw8n3vXx1VKxW1UbqHS',
                   '/ip6/::1/tcp/4001/ipfs/QmS2C4MjZsv2iP1UDMMLCYqJ4WeJw8n3vXx1VKxW1UbqHS'],
     'AgentVersion': 'go-ipfs/0.3.8-dev',
     'ID': 'QmS2C4MjZsv2iP1UDMMLCYqJ4WeJw8n3vXx1VKxW1UbqHS',
     'ProtocolVersion': 'ipfs/0.1.0',
     'PublicKey': '<KEY>}

Pass in API options:

.. code-block:: python

    >>> api.pin_ls(opts={'type':'all'})
    {'Keys': {'<KEY>': {'Count': 1,
                                                                 'Type': 'indirect'},
              'QmNQ1h6o1xJARvYzwmySPsuv9L5XfzS4WTvJSTAWwYRSd8': {'Count': 1,
                                                                 'Type': 'indirect'},
              ...

Add a directory and match against a filename pattern:

.. code-block:: python

    >>> api.add('photos', match='*.jpg')
    [{'Hash': 'QmcqBstfu5AWpXUqbucwimmWdJbu89qqYmE3WXVktvaXhX',
      'Name': 'photos/photo1.jpg'},
     {'Hash': 'QmSbmgg7kYwkSNzGLvWELnw1KthvTAMszN5TNg3XQ799Fu',
      'Name': 'photos/photo2.jpg'},
     {'Hash': 'Qma6K85PJ8dN3qWjxgsDNaMjWjTNy8ygUWXH2kfoq9bVxH',
      'Name': 'photos/photo3.jpg'}]

Or add a directory recursively:

.. code-block:: python

    >>> api.add('fake_dir', recursive=True)
{'fraction_non_alphanumeric': 0.17416436290525258, 'fraction_numerical': 0.04976124654435788, 'mean_word_length': 2.7796771130104463, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6974042', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1655, 'n_words': 246}