# Can I use ipfs as a library?

**URL:** <https://discuss.ipfs.tech/t/can-i-use-ipfs-as-a-library/7217>\
**Category:** Kubo\
**Created:** [February 7, 2020, 1:18pm UTC](https://discuss.ipfs.tech/t/can-i-use-ipfs-as-a-library/7217 "2020-02-07T13:18:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EnchanterIO](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/enchanterio/32/928_2.png) [@EnchanterIO](https://discuss.ipfs.tech/u/EnchanterIO)\
**Post date:** [February 7, 2020, 1:18pm UTC](https://discuss.ipfs.tech/t/can-i-use-ipfs-as-a-library/7217/1 "2020-02-07T13:18:57Z")

</div>

I am extending some IPFS functionalities and I would like to ask if it’s possible to use go-ipfs as library. For example to add a file I would use the same logic like the `add.go` cmd does:

```auto
https://github.com/ipfs/go-ipfs/blob/master/core/coreunix/add.go#L104
func (adder *Adder) add(reader io.Reader) (ipld.Node, error) {
	chnk, err := chunker.FromString(reader, adder.Chunker)
	if err != nil {
		return nil, err
	}
...

```

I am having some doubts because as AFIK, running an IPFS CLI cmd converts the commands into HTTP requests. Why is this done in this way? Some exclusive locks, shared resources?

---

<div class="post-metadata">

**Author:** ![EnchanterIO](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/enchanterio/32/928_2.png) [@EnchanterIO](https://discuss.ipfs.tech/u/EnchanterIO)\
**Post date:** [February 10, 2020, 10:07am UTC](https://discuss.ipfs.tech/t/can-i-use-ipfs-as-a-library/7217/2 "2020-02-10T10:07:42Z")

</div>

Update: run into an exclusive lock `ipfs/repo.lock failed: resource temporarily unavailable` but solved it by running the IPFS daemon from within my code and keeping the pointer to it. `AddHandler` seems to work. Let’s see about the cat.

---

<div class="post-metadata">

**Author:** ![EnchanterIO](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/enchanterio/32/928_2.png) [@EnchanterIO](https://discuss.ipfs.tech/u/EnchanterIO)\
**Post date:** [March 13, 2020, 8:54am UTC](https://discuss.ipfs.tech/t/can-i-use-ipfs-as-a-library/7217/3 "2020-03-13T08:54:56Z")

</div>

Update: all seems to work well. Although, some copy pasting because some IPFS business logic is unfortunately placed in the main/cmd package with many private functions.

---

<div class="post-metadata">

**Author:** ![hector](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/hector/32/178_2.png) [@hector](https://discuss.ipfs.tech/u/hector)\
**Post date:** [March 13, 2020, 9:20am UTC](https://discuss.ipfs.tech/t/can-i-use-ipfs-as-a-library/7217/4 "2020-03-13T09:20:38Z")

</div>

go-ipfs offers a public Core API that allows to do everything.

Check [https://github.com/ipfs/go-ipfs/tree/master/docs/examples/go-ipfs-as-a-library](https://github.com/ipfs/go-ipfs/tree/master/docs/examples/go-ipfs-as-a-library) (this is linked from the [docs.ipfs.io](http://docs.ipfs.io) page)
