A web application framework
Project description
What is Asita ?
Asita is a web application framework for python. It is designed to be easy to use and be more easy for javascript users to use python frameworks because it is based on express-js framework.
How to install Asita ?
Install this package using pip
$ pip install asita
Documentation
Get started
Exemple
from asita import Application
# creating application instance
app = Application()
# callback when web server is ready
def listen_callback(error):
if error:
raise error
print(f"Server listening on port 1000.")
# listen the webserver on port (for instance port 1000)
app.listen(1000, lambda error: listen_callback(error))
Application class
Methods
| Name | Parameters | Description |
|---|---|---|
| all(path, callback) | path: string, callback: function | Routes an HTTP request, where all is the HTTP method such as GET, PUT, POST, OATCH, DELETE, HEAD |
| post(path, callback) | path: string, callback: function | Routes HTTP POST requests |
| get(path, callback) | path: string, callback: function | Routes HTTP GET requests |
| put(path, callback) | path: string, callback: function | Routes HTTP PUT requests |
| patch(path, callback) | path: string, callback: function | Routes HTTP PATCH requests |
| delete(path, callback) | path: string, callback: function | Routes HTTP DELETE requests |
| head(path, callback) | path: string, callback: function | Routes HTTP HEAD requests |
| define_asset(name, directory) | name: string, directory: string | Define the asset directory access |
| listen(port, callback) | port: integer, callback: function | start listening a port |
Create a route
Exemple
# some awesome things check request and response methods :-)
def home(request, response):
pass
# "/" is the default path
app.all("/", lambda req, res: home(req, res))
To see more example, check the example file.
Request class
Attributs
| Name | Description |
|---|---|
| headers | headers of the request |
| session | client session |
| path | the url's path |
| request_type | type of request |
| server_address | address of the requested server |
| server_version | version of the requested server |
| protocol_version | version of the HTTP protocol |
| body | the body content of the POST request |
| query | url params |
Methods
| Name | Parameters | Description |
|---|---|---|
| get(value) | value: string | get a header of the request |
| accepts() | none | get types which are accepted |
Response class
Methods
| Name | Parameters | Description |
|---|---|---|
| status(code) | code: HttpResponses | return the response's state |
| set_header(key, value) | key: string, value: string | add/update headers |
| send(data, type?, encoded?) | data: object, type: string, encoded: boolean, is_asset: boolean | send response |
| json(data) | data: dict | write json on a page |
| render(path) | path: string | render html file. |
| end() | none | stop the current request |
? means that it is optionnal
Sessions class
| Name | Parameters | Description |
|---|---|---|
| add() | none | create new empty session |
| all() | none | get all sessions |
| has(sessionId) | key: string | verify if a session exists |
| get(sessionId) | key: string | get a session by id |
| delete(sessionId) | key: string | delete session by id |
| radnom_session_id @Static method | none | get all sessions |
Session class
| Name | Parameters | Description |
|---|---|---|
| get_session_id | none | get the id of the session |
| set(key, value) | key: string, value: string | add data to the client session |
| has(key) | key: string | verify if client session has the selected data |
| get(key) | key: string | get data from client session |
| delete(key) | key: string | delete data from client session |
| all() | none | get client session data |
Enumerations
HttpMethods
| HTTP Methods |
|---|
| GET |
| POST |
| PUT |
| DELETE |
| PATCH |
| HEAD |
| ALL |
HttpResponses
Client side
| Response types | Codes |
|---|---|
| OK | 200 |
| NO_CONTENT | 204 |
| UNAUTHORIZED | 401 |
| FORBIDDEN | 403 |
| NOT_FOUND | 404 |
| BAD_REQUEST | 400 |
Server side
| Response types | Codes |
|---|---|
| INTERNAL_SERVER_ERROR | 500 |
License
MIT LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asita-0.1.0.tar.gz.
File metadata
- Download URL: asita-0.1.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
000120659201392528822eca6569f55586e4cf04bd559090374fe7fc9b20c766
|
|
| MD5 |
68e60c3ba29dee9680238c8d3c2de8d2
|
|
| BLAKE2b-256 |
7df67f6650c607d7537b0a4074a8eb3933da875be35d1ad2763fb4c95acf75e9
|
File details
Details for the file asita-0.1.0-py3-none-any.whl.
File metadata
- Download URL: asita-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1881aa83f36573186e7782dc5e3412c7ace8988e32afab12628ba26b77c0c20d
|
|
| MD5 |
cea69ba0b38298afe609d1aecc9faaff
|
|
| BLAKE2b-256 |
8cd65100d608a9edf82eb3948b30046a1dfbc7ac3826564ad6b9bf674a28a2d9
|