以下是文档信息的英文翻译:
SA-Admin
Built on Sanic and leveraging the low-code framework AMIS for the frontend, SA-Admin simplifies frontend configuration for backend developers. With the power and lightweight nature of Sanic, it allows the backend manager to cover a wider range and achieve stronger functionality.
Installation
Currently, there is no PyPI installation method available. You can clone the repository to your local environment and run it directly:
python3 main.py
This will run and debug the application.
Usage
To use SA-Admin, you need to have a basic understanding of Sanic or Flask. The framework is loosely based on Django and uses the Tortoise ORM, Jinja2 templates, and the frontend is built with Baidu's low-code framework, AMIS. AMIS is a convenient frontend framework, but it may require some time to familiarize yourself with. With it, you can control the frontend pages directly using JSON.
The code includes comments that you can refer to directly.
Specific usage:
-
Database Configuration
Database configuration is in the
main.pyfile. If you need to switch to a different database, it is recommended to change it to MySQL or PostgreSQL because Tortoise supports asynchronous calls to these two databases directly, and the speed is really impressive.sa_config.TEST_DATABASE_URL = "sqlite://security_test_db.sqlite3"
-
Administrator Configuration
The initial password for the administrator is
SAdmin: SAdmin@123. If you need to change it to your own password, please modify the parameter.sa_config.INITIAL_ADMIN_PASSWORD = "SAdmin@123" # Password used when creating the initial admin account
-
Configure the port and run the command
If necessary, you can change the port:
app.run( host="127.0.0.1", port=22222, workers=1, debug=True, auto_reload=True )
Command Explanation:
-
workers=1: This configures multi-task processing. However, in high-concurrency situations, due to the time-consuming switch between parallelism and asynchronous operations, it may be slower than a single instance. If needed, it is recommended to run multiple processes, but for now, it's better not to useworkers. The choice depends on the actual scenario. -
auto_reload=True: This enables automatic reloading, which is very useful. You don't need to manually reload when you make code changes.
-
-
Design the frontend AMIS using an editor
For the first time using AMIS, take some time to read the AMIS documentation and understand how to use its components. I spent three days reading the documentation and getting familiar with various components.
You can directly use the AMIS online editor for interface design:
AMIS Editor:
https://aisuda.github.io/amis-editor-demo/#/hello-world
-
Edit the frontend components and copy the code directly.
-
In the frontend code area, create a JSON file and paste the code.
-
Reference the newly created code in the main framework.
The main framework file is
./admin/pages/site.json. To modify and reference it:- Copy the entire main framework code.
- Go to the AMIS editor, create a new page, paste the code, and add a column according to your preferences.
- After editing, copy it back to
site.json. Modify thedatasection to"schema": {}, which represents the content on the right side of the page.
You can also refer to my approach by saving the content of the newly added page as a separate JSON file and referencing it using schemaApi. Please refer to the site.json file for details.
Below is the JSON format for AMIS:
{
"status": 0, // Required item in the response
"msg": "", // Required item in the response
"data": { // JSON representing the elements of the page
"pages": [
{ // Title layer for the navigation bar
"label": "Home",
"url": "/", // URL for this layer to facilitate navigation to other layers
"redirect": "/login" // What page to navigate to when the page initializes
},
{
"label": "Function Navigation", // This layer becomes the navigation bar
"children": [ // Column layer for the navigation bar
{
"label": "Login/Register",
"url": "login",
"schema": {} // The content here represents the content on the right side of the page
},
{
"label": "The number of items here represents the number of columns in the navigation bar",
"url": "login",
"schema": {} // The content here represents the content on the right side of the page
}
]
}
]
}
}
Final Notes
This is a simple admin management interface. Please modify it according to your specific needs. With AMIS's features, it can roughly meet 90% of the requirements for admin management interfaces. For the remaining 10%, you may need some assistance from a frontend UI.
Performance Notes
I tested it with ApiPost7, but the results were not as ideal as others have claimed. It might be due to the use of multiple workers. I wrote a 60-second asynchronous request test [./test/access_url.pu], and the approximate number of requests handled by one process is between 20,000 and 26,000, with no packet loss. The request rate is approximately 400 requests per second under Sanic's processing.
When I ran three processes simultaneously, the number of simultaneous requests dropped to about 14,000, so I'm not sure if it's due to resource limitations on my laptop (Macbook14 M1) or something else. If you have sufficient resources, you can use my code or improve it and conduct further testing. On average, it's a stress load of about 2,300 requests per second, which I think is quite good for an admin dashboard.
When I ran ten processes, the number of simultaneous requests remained at around 14,000, with no errors.
Metadata
Release files for Sanic-SAdmin 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Sanic_SAdmin-0.1.1.tar.gz | 43.8 MB | Without provenance | Details for Sanic_SAdmin-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Sanic_SAdmin-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for Sanic_SAdmin-0.1.1-py3-none-any.whl |
Total release size: 87.8 MB
Release files / Sanic_SAdmin-0.1.1.tar.gz
| Download URL | Sanic_SAdmin-0.1.1.tar.gz |
|---|---|
| Size | 43.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d3e10e3dc6f126127706639be5747d0416e0c581b95a8c5c6a43833804cb974
|
|
BLAKE2b-256 checksum How to use checksums |
5c1f86991a95c1350248acef37f9e531d76c0640b65b76325befcf33b9443f72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / Sanic_SAdmin-0.1.1-py3-none-any.whl
| Download URL | Sanic_SAdmin-0.1.1-py3-none-any.whl |
|---|---|
| Size | 44.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d0d48f203d265414bf9250c879ceb875870049bd8f723287a2ac9106ae18374a
|
|
BLAKE2b-256 checksum How to use checksums |
085b2adcc14c621542bce789dd6ad9bea5fe1f4c7c3d41f9dc048ed5b18cc730
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for Sanic-SAdmin 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.