ipfslib


Nameipfslib JSON
Version 0.1.5 PyPI version JSON
download
home_page
SummaryIPFS Library for Python
upload_time2023-01-10 13:59:17
maintainer
docs_urlNone
authorChristian Remboldt
requires_python
license
keywords python ipfs api decentral networking ipns
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# ipfslib - Python IPFS Library

Simple wrapper for IPFS Kubo RPC API in Python



## Installation

    py -m pip install ipfslib



## Connect to API

First you need to create an object of the Connect class. For most usecases you don't need to specify any parameter as it's taking IPFS standard values:



    import ipfslib

    api = ipfslib.Connect()



If your API doesn't run on 127.0.0.1:5001, you can specify your own API endpoint:



    import ipfslib

    api = ipfslib.Connect("127.0.0.1", 5001)



## Interacting with IPFS

There are some tools to interact with the IPFS network. But as this library is still in development some of the functions could change in behaviour any time.



---

### IPFS.add()

Adding files to IPFS is simple.



    import ipfslib

    api = ipfslib.Connect()



    cid = ipfslib.IPFS.add(api, "helloworld.txt")

    print(cid)



---

### IPFS.cat()

Getting files from IPFS by the IPFS-Path. IPFS-Paths start with `/ipfs/` or `/ipns/`.



    import ipfslib

    api = ipfslib.Connect()



    path = "/ipfs/QmQrXZ4iXdEKQMiQT6GRg2Wy3vxb9exR25sYdaqoHwWWuR"

    text = ipfslib.IPFS.cat(api, path)



    print(text)



This function can also take a `mode` Parameter. It can either be set to `'t'` for "Text Mode", which returns a string in plain text. The other mode is `'b'`, which returns a string with byte data. This can be useful to retreive imagages from IPFS.



    import ipfslib

    api = ipfslib.Connect()



    path = "/ipfs/bafkreibih73gfbpgkmskacqtlsr4vtp47lmx24skh7jv27bnhsmhtivbeq"

    data = ipfslib.IPFS.cat(api, path, mode='b')



    with open('cat.png', 'wb') as img:

        img.write(data)



---



### IPFS.get()

With this function you can retreive data from an IPFS content identifier (CID).



    import ipfslib

    api = ipfslib.Connect()



    cid = "QmQrXZ4iXdEKQMiQT6GRg2Wy3vxb9exR25sYdaqoHwWWuR"

    text = ipfslib.IPFS.get(api, cid)



    print(text)



This function can also take the `mode` parameter, which can be either set to `'t'` or `'b'`. Read *IPFS.cat()* above to learn more.



---

### IPFS.rem()

Remove files from being provided to IPFS by their CID.



    import ipfslib

    api = ipfslib.Connect()



    cid = "QmQrXZ4iXdEKQMiQT6GRg2Wy3vxb9exR25sYdaqoHwWWuR"

    ipfslib.IPFS.rem(cid)



---

### IPFS.resolve()

Resolve IPNS names to get the CID they're pointing to.



    import ipfslib

    api = ipfslib.Connect()



    ipns_name = "k51qzi5uqu5dk37cdlr3ztr4457txgqmukmiex8ohkzyeeqpwfph2e21sks16s"

    cid = ipfslib.IPFS.resolve(api, ipns_name)



    print(cid)



## Interacting with IPNS Keys

Most of these tools can be used while offline, except of course `ipfslib.Key.publish()`.



---

### Key.generate()

This let's you generate a new IPNS Key.



    import ipfslib

    api = ipfslib.Connect()



    ipns_name = ipfslib.Key.generate(api, "test_key")



    print(ipns_name)



---

### Key.list()

Returns a list with dictionaries for every key. Each entry in the list has two keys (`Name` and `Id`). `Name` is the local name under which the key is stored. `Id` is the public IPNS Name of the key.



    import ipfslib

    api = ipfslib.Connect()



    keys = ipfslib.Key.list(api)



    # Get the IPNS name of the Key with the name "test_key"

    for key in keys:

        if key['Name'] == 'test_key':

            ipns_name = key['Id']

            break

    

    print(ipns_name)



---

### Key.publish()

This let's you link a CID to your IPNS Name.



    import ipfslib

    api = ipfslib.Connect()



    cid = "QmQrXZ4iXdEKQMiQT6GRg2Wy3vxb9exR25sYdaqoHwWWuR"



    ipfslib.Key.publish(api, cid, key_name='test_key')



If no key name is given to publish to, it will automatically publish to the 'self' key, which is your node's main key.



---

### Key.rename()

This let's you rename your IPNS keys locally. 



    import ipfslib

    api = ipfslib.Connect()



    old_name = "test_key"

    new_name = "project_key"



    ipfslib.Key.rename(api, old_name, new_name)



---



## Note

That's actually it for Version 0.1, thank you for considering to use my library. You can check out my blog to find out how I made this.



Blog: https://blog.remboldt.eu/ipfslib/  

GitHub: https://github.com/remboldt/ipfslib/

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "ipfslib",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,ipfs,api,decentral,networking,ipns",
    "author": "Christian Remboldt",
    "author_email": "remboldt@proton.me",
    "download_url": "https://files.pythonhosted.org/packages/9d/3b/9d4ca07ea7dad2b49ca61a94ac878241a9045db17e38c7d06d2791e1bccf/ipfslib-0.1.5.tar.gz",
    "platform": null,
    "description": "\r\n# ipfslib - Python IPFS Library\r\r\nSimple wrapper for IPFS Kubo RPC API in Python\r\r\n\r\r\n## Installation\r\r\n    py -m pip install ipfslib\r\r\n\r\r\n## Connect to API\r\r\nFirst you need to create an object of the Connect class. For most usecases you don't need to specify any parameter as it's taking IPFS standard values:\r\r\n\r\r\n    import ipfslib\r\r\n    api = ipfslib.Connect()\r\r\n\r\r\nIf your API doesn't run on 127.0.0.1:5001, you can specify your own API endpoint:\r\r\n\r\r\n    import ipfslib\r\r\n    api = ipfslib.Connect(\"127.0.0.1\", 5001)\r\r\n\r\r\n## Interacting with IPFS\r\r\nThere are some tools to interact with the IPFS network. But as this library is still in development some of the functions could change in behaviour any time.\r\r\n\r\r\n---\r\r\n### IPFS.add()\r\r\nAdding files to IPFS is simple.\r\r\n\r\r\n    import ipfslib\r\r\n    api = ipfslib.Connect()\r\r\n\r\r\n    cid = ipfslib.IPFS.add(api, \"helloworld.txt\")\r\r\n    print(cid)\r\r\n\r\r\n---\r\r\n### IPFS.cat()\r\r\nGetting files from IPFS by the IPFS-Path. IPFS-Paths start with `/ipfs/` or `/ipns/`.\r\r\n\r\r\n    import ipfslib\r\r\n    api = ipfslib.Connect()\r\r\n\r\r\n    path = \"/ipfs/QmQrXZ4iXdEKQMiQT6GRg2Wy3vxb9exR25sYdaqoHwWWuR\"\r\r\n    text = ipfslib.IPFS.cat(api, path)\r\r\n\r\r\n    print(text)\r\r\n\r\r\nThis function can also take a `mode` Parameter. It can either be set to `'t'` for \"Text Mode\", which returns a string in plain text. The other mode is `'b'`, which returns a string with byte data. This can be useful to retreive imagages from IPFS.\r\r\n\r\r\n    import ipfslib\r\r\n    api = ipfslib.Connect()\r\r\n\r\r\n    path = \"/ipfs/bafkreibih73gfbpgkmskacqtlsr4vtp47lmx24skh7jv27bnhsmhtivbeq\"\r\r\n    data = ipfslib.IPFS.cat(api, path, mode='b')\r\r\n\r\r\n    with open('cat.png', 'wb') as img:\r\r\n        img.write(data)\r\r\n\r\r\n---\r\r\n\r\r\n### IPFS.get()\r\r\nWith this function you can retreive data from an IPFS content identifier (CID).\r\r\n\r\r\n    import ipfslib\r\r\n    api = ipfslib.Connect()\r\r\n\r\r\n    cid = \"QmQrXZ4iXdEKQMiQT6GRg2Wy3vxb9exR25sYdaqoHwWWuR\"\r\r\n    text = ipfslib.IPFS.get(api, cid)\r\r\n\r\r\n    print(text)\r\r\n\r\r\nThis function can also take the `mode` parameter, which can be either set to `'t'` or `'b'`. Read *IPFS.cat()* above to learn more.\r\r\n\r\r\n---\r\r\n### IPFS.rem()\r\r\nRemove files from being provided to IPFS by their CID.\r\r\n\r\r\n    import ipfslib\r\r\n    api = ipfslib.Connect()\r\r\n\r\r\n    cid = \"QmQrXZ4iXdEKQMiQT6GRg2Wy3vxb9exR25sYdaqoHwWWuR\"\r\r\n    ipfslib.IPFS.rem(cid)\r\r\n\r\r\n---\r\r\n### IPFS.resolve()\r\r\nResolve IPNS names to get the CID they're pointing to.\r\r\n\r\r\n    import ipfslib\r\r\n    api = ipfslib.Connect()\r\r\n\r\r\n    ipns_name = \"k51qzi5uqu5dk37cdlr3ztr4457txgqmukmiex8ohkzyeeqpwfph2e21sks16s\"\r\r\n    cid = ipfslib.IPFS.resolve(api, ipns_name)\r\r\n\r\r\n    print(cid)\r\r\n\r\r\n## Interacting with IPNS Keys\r\r\nMost of these tools can be used while offline, except of course `ipfslib.Key.publish()`.\r\r\n\r\r\n---\r\r\n### Key.generate()\r\r\nThis let's you generate a new IPNS Key.\r\r\n\r\r\n    import ipfslib\r\r\n    api = ipfslib.Connect()\r\r\n\r\r\n    ipns_name = ipfslib.Key.generate(api, \"test_key\")\r\r\n\r\r\n    print(ipns_name)\r\r\n\r\r\n---\r\r\n### Key.list()\r\r\nReturns a list with dictionaries for every key. Each entry in the list has two keys (`Name` and `Id`). `Name` is the local name under which the key is stored. `Id` is the public IPNS Name of the key.\r\r\n\r\r\n    import ipfslib\r\r\n    api = ipfslib.Connect()\r\r\n\r\r\n    keys = ipfslib.Key.list(api)\r\r\n\r\r\n    # Get the IPNS name of the Key with the name \"test_key\"\r\r\n    for key in keys:\r\r\n        if key['Name'] == 'test_key':\r\r\n            ipns_name = key['Id']\r\r\n            break\r\r\n    \r\r\n    print(ipns_name)\r\r\n\r\r\n---\r\r\n### Key.publish()\r\r\nThis let's you link a CID to your IPNS Name.\r\r\n\r\r\n    import ipfslib\r\r\n    api = ipfslib.Connect()\r\r\n\r\r\n    cid = \"QmQrXZ4iXdEKQMiQT6GRg2Wy3vxb9exR25sYdaqoHwWWuR\"\r\r\n\r\r\n    ipfslib.Key.publish(api, cid, key_name='test_key')\r\r\n\r\r\nIf no key name is given to publish to, it will automatically publish to the 'self' key, which is your node's main key.\r\r\n\r\r\n---\r\r\n### Key.rename()\r\r\nThis let's you rename your IPNS keys locally. \r\r\n\r\r\n    import ipfslib\r\r\n    api = ipfslib.Connect()\r\r\n\r\r\n    old_name = \"test_key\"\r\r\n    new_name = \"project_key\"\r\r\n\r\r\n    ipfslib.Key.rename(api, old_name, new_name)\r\r\n\r\r\n---\r\r\n\r\r\n## Note\r\r\nThat's actually it for Version 0.1, thank you for considering to use my library. You can check out my blog to find out how I made this.\r\r\n\r\r\nBlog: https://blog.remboldt.eu/ipfslib/  \r\r\nGitHub: https://github.com/remboldt/ipfslib/\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "IPFS Library for Python",
    "version": "0.1.5",
    "split_keywords": [
        "python",
        "ipfs",
        "api",
        "decentral",
        "networking",
        "ipns"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9d3b9d4ca07ea7dad2b49ca61a94ac878241a9045db17e38c7d06d2791e1bccf",
                "md5": "18232b0bbb5b251195a16a7b24b29482",
                "sha256": "363012431381cbb93cad1a87333713b8d3285c33ac3e4b0c9386bcd4f59b2ddd"
            },
            "downloads": -1,
            "filename": "ipfslib-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "18232b0bbb5b251195a16a7b24b29482",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7582,
            "upload_time": "2023-01-10T13:59:17",
            "upload_time_iso_8601": "2023-01-10T13:59:17.812402Z",
            "url": "https://files.pythonhosted.org/packages/9d/3b/9d4ca07ea7dad2b49ca61a94ac878241a9045db17e38c7d06d2791e1bccf/ipfslib-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-10 13:59:17",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "ipfslib"
}
        
Elapsed time: 0.03514s