2020-05-04 15:20:36 +00:00
---
layout: default
parent: For developers
title: Making extensions
nav_order: 2
---
Making extensions
=================
2020-08-07 07:37:41 +00:00
Start off by copying the example extension in `lnbits/extensions/example` into your own:
```sh
cp lnbits/extensions/example lnbits/extensions/mysuperplugin -r # Let's not use dashes or anything; it doesn't like those.
cd lnbits/extensions/mysuperplugin
find . -type f -print0 | xargs -0 sed -i 's/example/mysuperplugin/g' # Change all occurrences of 'example' to your plugin name 'mysuperplugin'.
```
2022-07-11 11:40:46 +00:00
- if you are on macOS and having difficulty with 'sed', consider `brew install gnu-sed` and use 'gsed', without -0 option after xargs.
2020-08-07 07:37:41 +00:00
Going over the example extension's structure:
* views_api.py: This is where your public API would go. It will be exposed at "$DOMAIN/$PLUGIN/$ROUTE". For example: https://lnbits.com/mysuperplugin/api/v1/tools.
* views.py: The `/` path will show up as your plugin's home page in lnbits' UI. Other pages you can define yourself. The `templates` folder should explain itself in relation to this.
2020-09-04 01:39:52 +00:00
* migrations.py: Create database tables for your plugin. They'll be created automatically when you start lnbits.
2020-08-07 07:37:41 +00:00
... This document is a work-in-progress. Send pull requests if you get stuck, so others don't.
2020-09-02 12:31:44 +00:00
Adding new dependencies
-----------------------
2022-08-03 07:55:20 +00:00
If for some reason your extensions needs a new python package to work, you can add a new package using `venv` , or `poerty` :
2020-09-02 12:31:44 +00:00
```sh
2022-08-03 07:55:20 +00:00
$ poetry add < package >
# or
$ ./venv/bin/pip install < package >
2020-09-02 12:31:44 +00:00
```
**But we need an extra step to make sure LNbits doesn't break in production.**
2022-08-03 07:55:20 +00:00
Dependencies need to be added to `pyproject.toml` and `requirements.txt` , then tested by running on `venv` and `poetry` .
`nix` compatability can be tested with `nix build .#checks.x86_64-linux.vmTest` .
2020-09-02 12:31:44 +00:00