Skip to content

Commit b12d098

Browse files
committed
docs: restructure documentation
1 parent 9b06258 commit b12d098

7 files changed

+299
-19
lines changed

docs/_sidebar.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
<!-- docs/_sidebar.md -->
22

33
- [Home](/)
4-
- [Features](features.md)
5-
- [API](api.md)
4+
- [Installation](installation.md)
5+
- [Getting Started](getting-started.md)
6+
- [Community Resources](community-resources.md)
7+
- [Examples](examples.md)
8+
- [Feature Showcase](features.md)
69
- [Architecture](architecture.md)
710
- [Comparison](comparison.md)
8-
- [Plugins](plugins.md)
11+
- [API](api.md)
912
- [Future Roadmap](roadmap.md)
13+
- [Plugins](plugins.md)
1014
- [Sponsors](sponsors.md)
1115

docs/community-resources.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Community Resources
2+
3+
### Talks
4+
5+
- [EuroPython 2022](https://www.youtube.com/watch?v=AutugvJNVkY&)
6+
- [GeoPython 2022](https://www.youtube.com/watch?v=YCpbCQwbkd4)
7+
- [PyCon US 2022](https://www.youtube.com/watch?v=1IiL31tUEVk)
8+
- [PyCon Sweden 2021](https://www.youtube.com/watch?v=DK9teAs72Do)

docs/examples.md

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
## Examples of Using Robyn
2+
3+
Below are a few examples of real life use cases of Robyn.
4+
5+
### Creating a Simple HTTP Service
6+
```python3
7+
8+
from robyn import Robyn
9+
10+
app = Robyn(__file__)
11+
12+
@app.get("/")
13+
async def h(request):
14+
return "Hello, world!"
15+
16+
app.start(port=5000)
17+
18+
```
19+
20+
### Serving simple HTML Files
21+
```python3
22+
23+
from robyn import Robyn, static_file
24+
25+
app = Robyn(__file__)
26+
27+
@app.get("/")
28+
async def h(request):
29+
return static_file("./index.html")
30+
31+
app.start(port=5000)
32+
33+
```
34+
35+
36+
### Interaction with a Database
37+
38+
It should be fairly easy to make a crud app example. Here's a minimal example using Prisma(`pip install prisma-client-py`) with Robyn.
39+
40+
```py
41+
from robyn import Robyn
42+
from prisma import Prisma
43+
from prisma.models import User
44+
45+
app = Robyn(__file__)
46+
prisma = Prisma(auto_register=True)
47+
48+
@app.startup_handler
49+
async def startup_handler() -> None:
50+
await prisma.connect()
51+
52+
@app.shutdown_handler
53+
async def shutdown_handler() -> None:
54+
if prisma.is_connected():
55+
await prisma.disconnect()
56+
57+
@app.get("/")
58+
async def h():
59+
user = await User.prisma().create(
60+
data={
61+
"name": "Robert",
62+
},
63+
)
64+
return user.json(indent=2)
65+
66+
app.start(port=5000)
67+
```
68+
69+
Using this Prisma Schema:
70+
71+
```prisma
72+
datasource db {
73+
provider = "sqlite"
74+
url = "file:dev.db"
75+
}
76+
77+
generator py {
78+
provider = "prisma-client-py"
79+
}
80+
81+
model User {
82+
id String @id @default(cuid())
83+
name String
84+
}
85+
```
86+
87+
### Using Middleware
88+
```python3
89+
90+
from robyn import Robyn, static_file
91+
92+
app = Robyn(__file__)
93+
94+
@app.get("/")
95+
async def h(request):
96+
return static_file("./index.html")
97+
98+
app.start(port=5000)
99+
100+
```
101+
### A basic web socket chat app.
102+
Coming Soon....
103+
104+
### Using Robyn to send an email
105+
Coming Soon....

docs/features.md

+96-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,98 @@
11
## Features
2-
- #### Under active development!
3-
- #### Written in *Rust*, btw xD
4-
- #### A multithreaded Runtime
5-
- #### Extensible
6-
- #### A simple API
7-
- #### Sync and Async Function Support
8-
- #### Multithreaded file/directory serving
9-
- #### Dynamic URL Routing
10-
- #### Multi Core Scaling
11-
- #### Middlewares
12-
- #### WebSockets
13-
- #### Hot Reloading
14-
- #### Const Requests
15-
- #### Community First and truly FOSS!
16-
- #### Query Params
17-
- #### Events (Startup and Shutdown)
2+
3+
### Synchronous API
4+
```python3
5+
6+
@app.get(‘/’)
7+
def h():
8+
return “Hello, world”
9+
```
10+
11+
### Async API
12+
13+
```python3
14+
@app.get(‘/’)
15+
async def h():
16+
return “Hello, world”
17+
```
18+
19+
### Directory Serving
20+
21+
```python3
22+
app.add_directory(
23+
route=”/test_dir”,
24+
directory_path=”/build”,
25+
index_file=”index.html”
26+
)
27+
```
28+
29+
### Static File Serving
30+
31+
```python3
32+
from Robyn import static_file
33+
34+
@app.get(‘/’)
35+
async def test():
36+
return static_file(“./index.html”)
37+
```
38+
39+
### URL Routing
40+
41+
```python3
42+
@app.get("/test/:test_file")
43+
async def test(request):
44+
test_file = request["params"]["test_file"]
45+
return static_file("./index.html")
46+
```
47+
48+
### Multi Core Scaling
49+
50+
```python3
51+
python3 app.py \
52+
--processes=N \
53+
--workers=N
54+
```
55+
56+
### Middlewares
57+
58+
```python3
59+
@app.before_request("/")
60+
async def hello_before_request(request):
61+
print(request)
62+
return ""
63+
64+
@app.after_request("/")
65+
async def hello_after_request(request):
66+
print(request)
67+
return ""
68+
```
69+
70+
71+
### WebSockets
72+
73+
```python3
74+
from robyn import WS
75+
76+
websocket = WS(app, "/web_socket")
77+
78+
@websocket.on("message")
79+
async def connect(websocket_id):
80+
return Òhow are youÓ
81+
82+
@websocket.on("close")
83+
def close():
84+
return "GoodBye world, from ws"
85+
86+
@websocket.on("connect")
87+
async def message():
88+
return "Hello world, from ws"
89+
```
90+
91+
### Const Requests
92+
93+
```python3
94+
@app.get(‘/’, const=True)
95+
async def h():
96+
return “Hello, world”
97+
```
1898

docs/getting-started.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
## Getting Started.
2+
3+
We will go through the process of creating a "Hello, World!" app.
4+
5+
### Step 1: Creating a virtualenv
6+
7+
To ensure that there are isolated dependencies, we will use virtualenvironments.
8+
9+
```
10+
python3 -m venv venv
11+
```
12+
13+
### Step 2: Activate the virtualenv and install Robyn
14+
15+
#### Activating the virtualenv
16+
```
17+
source venv/bin/activate
18+
```
19+
20+
#### Installing Robyn
21+
```
22+
pip install robyn
23+
```
24+
25+
### Step 3: Creating the App.
26+
27+
- Create a file called `app.py`.
28+
29+
- In your favourite editor, open `app.py` and write the following.
30+
31+
```python
32+
33+
from robyn import Robyn
34+
35+
app = Robyn(__file__)
36+
37+
@app.get("/")
38+
async def h():
39+
return "Hello, world!"
40+
41+
app.start(port=5000, url="0.0.0.0") # url is optional, defaults to 127.0.0.1
42+
43+
```
44+
45+
Let us try to decipher the usage line by line.
46+
47+
> from robyn import Robyn
48+
49+
This statement just imports the Robyn structure from the robyn package.
50+
51+
> app = Robyn(__file__)
52+
53+
Here, we are creating the app object. We require the `__file__` object to mount the directory for hot reloading.
54+
55+
### Step 4. Running the service
56+
57+
You can just use the command
58+
59+
```
60+
python3 app.py
61+
```
62+
63+
if you want to run the production version, and
64+
65+
```
66+
python3 app.py --dev=true
67+
```
68+
if you want to enable hot reloading or the development version.
69+

docs/installation.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## 📦 Installation
2+
3+
You can simply use Pip for installation.
4+
5+
```
6+
pip install robyn
7+
```
8+
9+
Or, with [conda-forge](https://conda-forge.org/)
10+
11+
```
12+
conda install -c conda-forge robyn
13+
```

docs/usage.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
##

0 commit comments

Comments
 (0)