ipfslib


Nameipfslib JSON
Version 0.1.10 PyPI version JSON
download
home_pageNone
SummaryIPFS Library for Python
upload_time2024-10-04 16:27:59
maintainerNone
docs_urlNone
authorChristian Remboldt
requires_pythonNone
licenseNone
keywords python ipfs api decentral networking ipns web3
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)

This function can take the parameter `mode`. If `'t'` is passed, the file is opened in read mode (r). If `'b'` is passed, then the file is opened in read byte mode (rb).

---
### 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.remove()
With this function you can remove previously generated keys.

    import ipfslib
    api = ipfslib.Connect()

    ipfslib.Key.remove(api, key_name='test_key')

If you try to remove a non exsistent key the function will throw an exception.

---
### 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": null,
    "name": "ipfslib",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "python, ipfs, api, decentral, networking, ipns, web3",
    "author": "Christian Remboldt",
    "author_email": "christian@remboldt.eu",
    "download_url": "https://files.pythonhosted.org/packages/c5/63/35e2cb337320dd7fa7624548141dc1b3ca4cf389e9863d83efe924c02fe2/ipfslib-0.1.10.tar.gz",
    "platform": null,
    "description": "\n# ipfslib - Python IPFS Library\nSimple wrapper for IPFS Kubo RPC API in Python\n\n## Installation\n    py -m pip install ipfslib\n\n## Connect to API\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:\n\n    import ipfslib\n    api = ipfslib.Connect()\n\nIf your API doesn't run on 127.0.0.1:5001, you can specify your own API endpoint:\n\n    import ipfslib\n    api = ipfslib.Connect(\"127.0.0.1\", 5001)\n\n## Interacting with IPFS\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.\n\n---\n### IPFS.add()\nAdding files to IPFS is simple.\n\n    import ipfslib\n    api = ipfslib.Connect()\n\n    cid = ipfslib.IPFS.add(api, \"helloworld.txt\")\n    print(cid)\n\nThis function can take the parameter `mode`. If `'t'` is passed, the file is opened in read mode (r). If `'b'` is passed, then the file is opened in read byte mode (rb).\n\n---\n### IPFS.cat()\nGetting files from IPFS by the IPFS-Path. IPFS-Paths start with `/ipfs/` or `/ipns/`.\n\n    import ipfslib\n    api = ipfslib.Connect()\n\n    path = \"/ipfs/QmQrXZ4iXdEKQMiQT6GRg2Wy3vxb9exR25sYdaqoHwWWuR\"\n    text = ipfslib.IPFS.cat(api, path)\n\n    print(text)\n\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.\n\n    import ipfslib\n    api = ipfslib.Connect()\n\n    path = \"/ipfs/bafkreibih73gfbpgkmskacqtlsr4vtp47lmx24skh7jv27bnhsmhtivbeq\"\n    data = ipfslib.IPFS.cat(api, path, mode='b')\n\n    with open('cat.png', 'wb') as img:\n        img.write(data)\n\n---\n\n### IPFS.get()\nWith this function you can retreive data from an IPFS content identifier (CID).\n\n    import ipfslib\n    api = ipfslib.Connect()\n\n    cid = \"QmQrXZ4iXdEKQMiQT6GRg2Wy3vxb9exR25sYdaqoHwWWuR\"\n    text = ipfslib.IPFS.get(api, cid)\n\n    print(text)\n\nThis function can also take the `mode` parameter, which can be either set to `'t'` or `'b'`. Read *IPFS.cat()* above to learn more.\n\n---\n### IPFS.rem()\nRemove files from being provided to IPFS by their CID.\n\n    import ipfslib\n    api = ipfslib.Connect()\n\n    cid = \"QmQrXZ4iXdEKQMiQT6GRg2Wy3vxb9exR25sYdaqoHwWWuR\"\n    ipfslib.IPFS.rem(cid)\n\n---\n### IPFS.resolve()\nResolve IPNS names to get the CID they're pointing to.\n\n    import ipfslib\n    api = ipfslib.Connect()\n\n    ipns_name = \"k51qzi5uqu5dk37cdlr3ztr4457txgqmukmiex8ohkzyeeqpwfph2e21sks16s\"\n    cid = ipfslib.IPFS.resolve(api, ipns_name)\n\n    print(cid)\n\n## Interacting with IPNS Keys\nMost of these tools can be used while offline, except of course `ipfslib.Key.publish()`.\n\n---\n### Key.generate()\nThis let's you generate a new IPNS Key.\n\n    import ipfslib\n    api = ipfslib.Connect()\n\n    ipns_name = ipfslib.Key.generate(api, \"test_key\")\n\n    print(ipns_name)\n\n---\n### Key.list()\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.\n\n    import ipfslib\n    api = ipfslib.Connect()\n\n    keys = ipfslib.Key.list(api)\n\n    # Get the IPNS name of the Key with the name \"test_key\"\n    for key in keys:\n        if key['Name'] == 'test_key':\n            ipns_name = key['Id']\n            break\n    \n    print(ipns_name)\n\n---\n### Key.publish()\nThis let's you link a CID to your IPNS Name.\n\n    import ipfslib\n    api = ipfslib.Connect()\n\n    cid = \"QmQrXZ4iXdEKQMiQT6GRg2Wy3vxb9exR25sYdaqoHwWWuR\"\n\n    ipfslib.Key.publish(api, cid, key_name='test_key')\n\nIf no key name is given to publish to, it will automatically publish to the 'self' key, which is your node's main key.\n\n---\n### Key.remove()\nWith this function you can remove previously generated keys.\n\n    import ipfslib\n    api = ipfslib.Connect()\n\n    ipfslib.Key.remove(api, key_name='test_key')\n\nIf you try to remove a non exsistent key the function will throw an exception.\n\n---\n### Key.rename()\nThis let's you rename your IPNS keys locally. \n\n    import ipfslib\n    api = ipfslib.Connect()\n\n    old_name = \"test_key\"\n    new_name = \"project_key\"\n\n    ipfslib.Key.rename(api, old_name, new_name)\n\n---\n\n## Note\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.\n\nBlog: https://blog.remboldt.eu/ipfslib/  \nGitHub: https://github.com/remboldt/ipfslib/\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "IPFS Library for Python",
    "version": "0.1.10",
    "project_urls": null,
    "split_keywords": [
        "python",
        " ipfs",
        " api",
        " decentral",
        " networking",
        " ipns",
        " web3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "50c6f71eb5657d8e340a71ef82cdede6e899d4ef9f49da439151e193aaa46e1b",
                "md5": "11ad3939db57911e59a6f137bc50334c",
                "sha256": "b367844d62a4c3b2e8bd8f22f11e4b9ca773002a606d66101e7e309bc69d9f57"
            },
            "downloads": -1,
            "filename": "ipfslib-0.1.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "11ad3939db57911e59a6f137bc50334c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8495,
            "upload_time": "2024-10-04T16:27:58",
            "upload_time_iso_8601": "2024-10-04T16:27:58.266986Z",
            "url": "https://files.pythonhosted.org/packages/50/c6/f71eb5657d8e340a71ef82cdede6e899d4ef9f49da439151e193aaa46e1b/ipfslib-0.1.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c56335e2cb337320dd7fa7624548141dc1b3ca4cf389e9863d83efe924c02fe2",
                "md5": "4a7b12dd82293df207e836a8678e1a56",
                "sha256": "b629868d177f371e4fbe5cdac0ba69b707e6e02c688122c2484c84a75e9b8057"
            },
            "downloads": -1,
            "filename": "ipfslib-0.1.10.tar.gz",
            "has_sig": false,
            "md5_digest": "4a7b12dd82293df207e836a8678e1a56",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7027,
            "upload_time": "2024-10-04T16:27:59",
            "upload_time_iso_8601": "2024-10-04T16:27:59.403346Z",
            "url": "https://files.pythonhosted.org/packages/c5/63/35e2cb337320dd7fa7624548141dc1b3ca4cf389e9863d83efe924c02fe2/ipfslib-0.1.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-04 16:27:59",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "ipfslib"
}
        
Elapsed time: 0.41053s