-
-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
299 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
<!-- docs/_sidebar.md --> | ||
|
||
- [Home](/) | ||
- [Features](features.md) | ||
- [API](api.md) | ||
- [Installation](installation.md) | ||
- [Getting Started](getting-started.md) | ||
- [Community Resources](community-resources.md) | ||
- [Examples](examples.md) | ||
- [Feature Showcase](features.md) | ||
- [Architecture](architecture.md) | ||
- [Comparison](comparison.md) | ||
- [Plugins](plugins.md) | ||
- [API](api.md) | ||
- [Future Roadmap](roadmap.md) | ||
- [Plugins](plugins.md) | ||
- [Sponsors](sponsors.md) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## Community Resources | ||
|
||
### Talks | ||
|
||
- [EuroPython 2022](https://www.youtube.com/watch?v=AutugvJNVkY&) | ||
- [GeoPython 2022](https://www.youtube.com/watch?v=YCpbCQwbkd4) | ||
- [PyCon US 2022](https://www.youtube.com/watch?v=1IiL31tUEVk) | ||
- [PyCon Sweden 2021](https://www.youtube.com/watch?v=DK9teAs72Do) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
## Examples of Using Robyn | ||
|
||
Below are a few examples of real life use cases of Robyn. | ||
|
||
### Creating a Simple HTTP Service | ||
```python3 | ||
|
||
from robyn import Robyn | ||
|
||
app = Robyn(__file__) | ||
|
||
@app.get("/") | ||
async def h(request): | ||
return "Hello, world!" | ||
|
||
app.start(port=5000) | ||
|
||
``` | ||
|
||
### Serving simple HTML Files | ||
```python3 | ||
|
||
from robyn import Robyn, static_file | ||
|
||
app = Robyn(__file__) | ||
|
||
@app.get("/") | ||
async def h(request): | ||
return static_file("./index.html") | ||
|
||
app.start(port=5000) | ||
|
||
``` | ||
|
||
|
||
### Interaction with a Database | ||
|
||
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. | ||
|
||
```py | ||
from robyn import Robyn | ||
from prisma import Prisma | ||
from prisma.models import User | ||
|
||
app = Robyn(__file__) | ||
prisma = Prisma(auto_register=True) | ||
|
||
@app.startup_handler | ||
async def startup_handler() -> None: | ||
await prisma.connect() | ||
|
||
@app.shutdown_handler | ||
async def shutdown_handler() -> None: | ||
if prisma.is_connected(): | ||
await prisma.disconnect() | ||
|
||
@app.get("/") | ||
async def h(): | ||
user = await User.prisma().create( | ||
data={ | ||
"name": "Robert", | ||
}, | ||
) | ||
return user.json(indent=2) | ||
|
||
app.start(port=5000) | ||
``` | ||
|
||
Using this Prisma Schema: | ||
|
||
```prisma | ||
datasource db { | ||
provider = "sqlite" | ||
url = "file:dev.db" | ||
} | ||
generator py { | ||
provider = "prisma-client-py" | ||
} | ||
model User { | ||
id String @id @default(cuid()) | ||
name String | ||
} | ||
``` | ||
|
||
### Using Middleware | ||
```python3 | ||
|
||
from robyn import Robyn, static_file | ||
|
||
app = Robyn(__file__) | ||
|
||
@app.get("/") | ||
async def h(request): | ||
return static_file("./index.html") | ||
|
||
app.start(port=5000) | ||
|
||
``` | ||
### A basic web socket chat app. | ||
Coming Soon.... | ||
|
||
### Using Robyn to send an email | ||
Coming Soon.... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,98 @@ | ||
## Features | ||
- #### Under active development! | ||
- #### Written in *Rust*, btw xD | ||
- #### A multithreaded Runtime | ||
- #### Extensible | ||
- #### A simple API | ||
- #### Sync and Async Function Support | ||
- #### Multithreaded file/directory serving | ||
- #### Dynamic URL Routing | ||
- #### Multi Core Scaling | ||
- #### Middlewares | ||
- #### WebSockets | ||
- #### Hot Reloading | ||
- #### Const Requests | ||
- #### Community First and truly FOSS! | ||
- #### Query Params | ||
- #### Events (Startup and Shutdown) | ||
|
||
### Synchronous API | ||
```python3 | ||
|
||
@app.get(‘/’) | ||
def h(): | ||
return “Hello, world†| ||
``` | ||
|
||
### Async API | ||
|
||
```python3 | ||
@app.get(‘/’) | ||
async def h(): | ||
return “Hello, world†| ||
``` | ||
|
||
### Directory Serving | ||
|
||
```python3 | ||
app.add_directory( | ||
route=â€/test_dirâ€, | ||
directory_path=â€/buildâ€, | ||
index_file=â€index.html†| ||
) | ||
``` | ||
|
||
### Static File Serving | ||
|
||
```python3 | ||
from Robyn import static_file | ||
|
||
@app.get(‘/’) | ||
async def test(): | ||
return static_file(“./index.htmlâ€) | ||
``` | ||
|
||
### URL Routing | ||
|
||
```python3 | ||
@app.get("/test/:test_file") | ||
async def test(request): | ||
test_file = request["params"]["test_file"] | ||
return static_file("./index.html") | ||
``` | ||
|
||
### Multi Core Scaling | ||
|
||
```python3 | ||
python3 app.py \ | ||
--processes=N \ | ||
--workers=N | ||
``` | ||
|
||
### Middlewares | ||
|
||
```python3 | ||
@app.before_request("/") | ||
async def hello_before_request(request): | ||
print(request) | ||
return "" | ||
|
||
@app.after_request("/") | ||
async def hello_after_request(request): | ||
print(request) | ||
return "" | ||
``` | ||
|
||
|
||
### WebSockets | ||
|
||
```python3 | ||
from robyn import WS | ||
|
||
websocket = WS(app, "/web_socket") | ||
|
||
@websocket.on("message") | ||
async def connect(websocket_id): | ||
return Òhow are youÓ | ||
|
||
@websocket.on("close") | ||
def close(): | ||
return "GoodBye world, from ws" | ||
|
||
@websocket.on("connect") | ||
async def message(): | ||
return "Hello world, from ws" | ||
``` | ||
|
||
### Const Requests | ||
|
||
```python3 | ||
@app.get(‘/’, const=True) | ||
async def h(): | ||
return “Hello, world†| ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
## Getting Started. | ||
|
||
We will go through the process of creating a "Hello, World!" app. | ||
|
||
### Step 1: Creating a virtualenv | ||
|
||
To ensure that there are isolated dependencies, we will use virtualenvironments. | ||
|
||
``` | ||
python3 -m venv venv | ||
``` | ||
|
||
### Step 2: Activate the virtualenv and install Robyn | ||
|
||
#### Activating the virtualenv | ||
``` | ||
source venv/bin/activate | ||
``` | ||
|
||
#### Installing Robyn | ||
``` | ||
pip install robyn | ||
``` | ||
|
||
### Step 3: Creating the App. | ||
|
||
- Create a file called `app.py`. | ||
|
||
- In your favourite editor, open `app.py` and write the following. | ||
|
||
```python | ||
|
||
from robyn import Robyn | ||
|
||
app = Robyn(__file__) | ||
|
||
@app.get("/") | ||
async def h(): | ||
return "Hello, world!" | ||
|
||
app.start(port=5000, url="0.0.0.0") # url is optional, defaults to 127.0.0.1 | ||
|
||
``` | ||
|
||
Let us try to decipher the usage line by line. | ||
|
||
> from robyn import Robyn | ||
This statement just imports the Robyn structure from the robyn package. | ||
|
||
> app = Robyn(__file__) | ||
Here, we are creating the app object. We require the `__file__` object to mount the directory for hot reloading. | ||
|
||
### Step 4. Running the service | ||
|
||
You can just use the command | ||
|
||
``` | ||
python3 app.py | ||
``` | ||
|
||
if you want to run the production version, and | ||
|
||
``` | ||
python3 app.py --dev=true | ||
``` | ||
if you want to enable hot reloading or the development version. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## 📦 Installation | ||
|
||
You can simply use Pip for installation. | ||
|
||
``` | ||
pip install robyn | ||
``` | ||
|
||
Or, with [conda-forge](https://conda-forge.org/) | ||
|
||
``` | ||
conda install -c conda-forge robyn | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
## |