Skip to content

Commit c2145b4

Browse files
authored
more docs (#91)
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
1 parent 7801ebb commit c2145b4

File tree

13 files changed

+185
-29
lines changed

13 files changed

+185
-29
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ answer newbie questions, and generally made NC-Py-API that much better:
44

55
Andrey Borysenko <andrey18106x@gmail.com>
66
Alexander Piskun <bigcat88@icloud.com>
7+
CooperGerman <https://github.com/CooperGerman>
78
<Please alphabetize new entries>
89

910
A big THANK YOU goes to:

README.md

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<p align="center">
2+
<img src="https://raw.githubusercontent.com/cloud-py-api/nc_py_api/docs/resources/logo_py_nc.png" alt="NcPyApi logo">
3+
</p>
4+
15
# Official Nextcloud Python Framework
26

37
[![Analysis & Coverage](https://github.com/cloud-py-api/nc_py_api/actions/workflows/analysis-coverage.yml/badge.svg)](https://github.com/cloud-py-api/nc_py_api/actions/workflows/analysis-coverage.yml)
@@ -11,22 +15,42 @@
1115

1216
Python library that provides a robust and well-documented API that allows developers to interact with and extend Nextcloud's functionality.
1317

14-
### Basic Features:
15-
* Operations with Files and Folders
16-
* ~~Operations with Trash bin and File versions~~
17-
* Operations with Users and User Groups
18-
* User status
19-
* Weather status
20-
* Notifications support
21-
* Shares support
22-
* ~~Talk support~~
23-
24-
### Extended Features with AppEcosystemV2:
25-
* Defining callback routes with `FastAPI` for Nextcloud
26-
* Registering UI elements in Nextcloud
27-
* Storing logs to the `nextcloud.log` file
28-
* Get/save key-value pairs in AppConfigEx/PreferencesEx tables.
29-
* **Tons of the cool stuff that is coming soon**
18+
### The key features are:
19+
* **Fast**: High performance, and as low-latency as possible.
20+
* **Intuitive**: Fast to code, easy to use.
21+
* **Reliable**: Minimum number of incompatible changes.
22+
* **Robust**: All code is covered with tests as much as possible.
23+
* **Easy**: Designed to be easy to use with excellent documentation.
24+
25+
### Capabilities
26+
| **_Capability_** | Nextcloud 26 | Nextcloud 27 | Nextcloud 28 |
27+
|------------------|:------------:|:------------:|:------------:|
28+
| Filesystem* ||||
29+
| Shares ||||
30+
| Users & Groups ||||
31+
| User status ||||
32+
| Weather status ||||
33+
| Notifications ||||
34+
| Nextcloud Talk ||||
35+
| Text Provider** ||||
36+
37+
&ast;missing `Trash bin` and `File version` support.<br>
38+
&ast;&ast;available only for NextcloudApp
39+
40+
### Differences between the NextCloud and NextCloudApp classes
41+
42+
The **NextCloud** class functions as a standard NextCloud client,
43+
enabling you to make API requests using a username and password.
44+
45+
On the other hand, the **NextCloudApp** class is designed for creating applications for NextCloud.<br>
46+
It uses the [AppEcosystem](https://github.com/cloud-py-api/app_ecosystem_v2) to allow
47+
applications to impersonate users through a separate authentication mechanism.
48+
49+
Both classes offer most of the same APIs,
50+
but NextCloudApp has a broader selection since applications typically require access to more APIs.
51+
52+
Any code written for the NextCloud class can easily be adapted for use with the NextCloudApp class,
53+
as long as it doesn't involve calls that require user password verification.
3054

3155
### Support
3256

@@ -37,19 +61,31 @@ You can support us in several ways:
3761
- 💁 Resolve some Issue or create a Pull Request (contribute to this project)
3862
- 🙏 Write an example of its use or correct a typo in the documentation.
3963

40-
### 🚀 How to start
41-
42-
In a very close near future we will publish examples
43-
44-
### More Information
64+
## More Information
4565

4666
- [Documentation](https://cloud-py-api.github.io/nc_py_api/)
4767
- [First steps](https://cloud-py-api.github.io/nc_py_api/FirstSteps.html)
48-
- [Writing a simple Nextcloud application](to-do)
49-
- [Writing a Nextcloud System Application](to-do)
68+
- [More APIs](https://cloud-py-api.github.io/nc_py_api/MoreAPIs.html)
69+
- [Writing a simple Nextcloud application](https://cloud-py-api.github.io/nc_py_api/NextcloudApp.html)
70+
- [Writing a Nextcloud System Application](https://cloud-py-api.github.io/nc_py_api/NextcloudSysApp.html)
5071
- [Examples](https://github.com/cloud-py-api/nc_py_api/tree/main/examples)
5172
- [Contribute](https://github.com/cloud-py-api/nc_py_api/blob/main/.github/CONTRIBUTING.md)
5273
- [Discussions](https://github.com/cloud-py-api/nc_py_api/discussions)
5374
- [Issues](https://github.com/cloud-py-api/nc_py_api/issues)
5475
- [Setting up dev environment](https://cloud-py-api.github.io/nc_py_api/DevSetup.html)
5576
- [Changelog](https://github.com/cloud-py-api/nc_py_api/blob/main/CHANGELOG.md)
77+
78+
### Motivation
79+
80+
_Python's language, elegant and clear,_<br>
81+
_Weaves logic's threads without fear,_<br>
82+
_And in the sky, where clouds take form,_<br>
83+
_Nextcloud emerges, a digital norm._<br>
84+
85+
_Together they stand, a duo bright,_<br>
86+
_Python and Nextcloud, day and night,_<br>
87+
_In a digital dance, they guide and sail,_<br>
88+
_Shaping tomorrow, where new ideas prevail._<br>
89+
90+
#### **Know that we are always here to support and assist you on your journey.**
91+
### P.S: **_Good luck, and we hope you have fun!_**

docs/FirstSteps.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ For this part, you will need an environment with **nc_py_api** installed and Nex
77

88
Full support is only available from version ``27.1`` of Nextcloud.
99

10-
Nextcloud client
11-
^^^^^^^^^^^^^^^^
1210

1311
.. note:: In many cases, even if you want to develop an application,
1412
it's a good idea to first debug and develop part of it as a client.
1513

16-
Creation
17-
""""""""
14+
Creating Nextcloud client class
15+
"""""""""""""""""""""""""""""""
1816

1917
.. code-block:: python
2018
@@ -92,3 +90,11 @@ Example of using ``file.find()`` to search for file objects.
9290
.. note:: We welcome the idea of how to make the definition of search queries more friendly.
9391

9492
.. literalinclude:: ../examples/as_client/files/find.py
93+
94+
Conclusion
95+
""""""""""
96+
97+
Once you have a good understanding of working with files, you can move on to more APIs.
98+
99+
You don't have to learn them all at the same time, but it's good to at least have a general idea, so let's go with
100+
:ref:`more-apis`!

docs/MoreAPIs.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.. _more-apis:
2+
3+
More APIs
4+
=========

docs/NextcloudApp.rst

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Writing a Nextcloud Application
2+
===============================
3+
4+
This chapter assumes that you are already familiar with the `concepts <https://cloud-py-api.github.io/app_ecosystem_v2/Concepts.html>`_ of the AppEcosystem.
5+
6+
As a first step, let's take a look at the structure of a basic Python application.
7+
8+
Skeleton
9+
--------
10+
11+
.. literalinclude:: ../examples/as_app/skeleton/src/main.py
12+
13+
What's going on in the skeleton?
14+
15+
First, it's important to understand that an external application acts more like a microservice, with its endpoints being called by Nextcloud.
16+
17+
Therefore, when the application receives a request at the endpoint ``/enable``,
18+
it should register all its functionalities in the cloud and wait for requests from Nextcloud.
19+
20+
.. note:: This doesn't apply to system applications, which will be covered in the next chapter.
21+
22+
So, calling:
23+
24+
.. code-block:: python
25+
26+
set_handlers(APP, enabled_handler)
27+
28+
will register an **enabled_handler** that will be called **both when the application is enabled and disabled**.
29+
30+
During the enablement process, you should register all the functionalities that your application offers
31+
in the **enabled_handler** and remove them during the disablement process.
32+
33+
The API is designed so that you don't have to check whether an endpoint is already registered
34+
(e.g., in case of a malfunction or if the administrator manually altered something in the Nextcloud database).
35+
The API will not fail, and in such cases, it will simply re-register without error.
36+
37+
If any error prevents your application from functioning, you should provide a brief description in the return instead
38+
of an empty string, and log comprehensive information that will assist the administrator in addressing the issue.
39+
40+
Debugging
41+
---------
42+
43+
Debugging an application within Docker and rebuilding it from scratch each time can be cumbersome.
44+
Therefore, a manual deployment option has been specifically designed for this purpose.
45+
46+
First register ``manual_install`` daemon:
47+
48+
.. code-block:: shell
49+
50+
php occ app_ecosystem_v2:daemon:register manual_install "Manual Install" manual-install 0 0 0
51+
52+
Then, launch your application. Since this is a manual deployment, it's your responsibility to set minimum of the environment variables.
53+
Here they are:
54+
55+
* APP_ID - ID of the application.
56+
* APP_PORT - Port on which application listen for the requests from the Nextcloud.
57+
* APP_SECRET - Secret for ``hmac`` signature generation.
58+
* APP_VERSION - Version of the application.
59+
* AE_VERSION - Version of the AppEcosystem.
60+
* NEXTCLOUD_URL - URL at which the application can access the Nextcloud API.
61+
62+
You can find values for these environment variables in the **Skeleton** or **ToGif** run configurations.
63+
64+
After launching your application, execute the following command in the Nextcloud container:
65+
66+
.. code-block:: shell
67+
68+
php occ app_ecosystem_v2:app:register YOUR_APP_ID manual_install --json-info \
69+
"{\"appid\":\"YOUR_APP_ID\",\"name\":\"YOUR_APP_DISPLAY_NAME\",\"daemon_config_name\":\"manual_install\",\"version\":\"YOU_APP_VERSION\",\"secret\":\"YOUR_APP_SECRET\",\"host\":\"host.docker.internal\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"port\":SELECTED_PORT,\"protocol\":\"http\",\"system_app\":0}" \
70+
-e --force-scopes
71+
72+
You can see how **nc_py_api** registers in ``scripts/dev_register.sh``.
73+
74+
It's advisable to write these steps as commands in a Makefile for quick use.
75+
76+
Examples for such Makefiles can be found in this repository:
77+
`Skeleton <https://github.com/cloud-py-api/nc_py_api/blob/main/examples/as_app/skeleton/Makefile>`_ ,
78+
`ToGif <https://github.com/cloud-py-api/nc_py_api/blob/main/examples/as_app/to_gif/Makefile>`_ ,
79+
`nc_py_api <https://github.com/cloud-py-api/nc_py_api/blob/main/scripts/dev_register.sh>`_
80+
81+
During the execution of `php occ app_ecosystem_v2:app:register`, the **enabled_handler** will be called,
82+
as we pass the flag ``-e``, meaning ``enable after registration``.
83+
84+
This is likely all you need to start debugging and developing an application for Nextcloud.
85+
86+
Pack & Deploy
87+
-------------
88+
89+
Before reading this chapter, please review the basic information about deployment
90+
and the currently supported types of
91+
`deployments configurations <https://cloud-py-api.github.io/app_ecosystem_v2/DeployConfigurations.html>`_ in the AppEcosystem documentation.
92+
93+
to-do
94+
95+
From skeleton to ToGif
96+
----------------------
97+
98+
to-do

docs/NextcloudSysApp.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Writing System Nextcloud Application
2+
====================================

docs/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Have a great time with Python and Nextcloud!
2929

3030
Installation
3131
FirstSteps
32+
MoreAPIs
33+
NextcloudApp
34+
NextcloudSysApp
3235
Options
3336
reference/index.rst
3437
DevSetup

docs/resources/logo_py_nc.png

304 KB
Loading

examples/as_app/skeleton/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ run27:
4343

4444
.PHONY: manual_register
4545
manual_register:
46+
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:unregister skeleton --silent || true
4647
docker exec master-nextcloud-1 sudo -u www-data php occ app_ecosystem_v2:app:register skeleton manual_install --json-info \
4748
"{\"appid\":\"skeleton\",\"name\":\"App Skeleton\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9030,\"scopes\":{\"required\":[],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
4849
-e --force-scopes

examples/as_app/skeleton/src/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ def enabled_handler(enabled: bool, nc: NextcloudApp) -> str:
2323
return ""
2424

2525

26+
# Of course, you can use `FastAPI lifespan: <https://fastapi.tiangolo.com/advanced/events/#lifespan>` instead of this.
27+
# The only requirement for the application is to define `/enabled` and `/heartbeat` handlers.
2628
@APP.on_event("startup")
2729
def initialization():
2830
set_handlers(APP, enabled_handler)
2931

3032

3133
if __name__ == "__main__":
34+
# Wrapper around `uvicorn.run`.
35+
# You are free to call it directly, just use `APP_HOST` and `APP_PORT` from the environment.
3236
run_app("main:APP", log_level="trace")

0 commit comments

Comments
 (0)