NetJin


NameNetJin JSON
Version 1.1.1 PyPI version JSON
download
home_pageNone
SummaryNetJin is a lightweight web server implemented in Python using sockets. It provides a simple implementation of the HTTP protocol, allowing users to build and run web applications with ease.
upload_time2024-11-29 03:39:49
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords pythonframework webframework webserver
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # NetJin - Simple Python Web Server Implementation

## Overview

`NetJin` is a lightweight web server implemented in Python using sockets. It provides a simple implementation of the HTTP protocol, allowing users to build and run web applications with ease.

## Features

-   **Routing**: Easily define routes for different URLs and HTTP methods.
-   **Request Handling**: Handle incoming HTTP requests and process them accordingly.
-   **Response Rendering**: Render HTML templates for generating dynamic content and return other responses as well.
-   **Error Handling**: Customizable error handling for managing HTTP errors.

## Installation

You can install `NetJin` using pip:

```bash
pip install WebServer
```

Alternatively, you can clone or download the repository and include the `NetJin` file in your project directory.

## Usage

1. Import the necessary classes:

    ```python
    from WebServer import WebServer, Request, Response
    ```

2. Create an instance of the `WebServer` class:

    ```python
    app = WebServer(debug=True)
    ```

3. Define routes using the `@app.route()` decorator, specifying the URL path and supported HTTP methods. For example:

    ```python
    @app.route("/", methods=["GET"])
    def home(request: Request, response: response) -> None:
        return response.render("index") # This corresponse to index.html
    ```

4. Implement functions to handle each route, receiving `Response` and `Request` objects as parameters.

5. Run the server:

    ```python
    if __name__ == "__main__":
        app.run()
    ```

## Settings

To configure your project, create a file named `Settings.py` in a directory named `Configurations` at the root of your project. Define the required variables as needed. For example:

```python
from pathlib import Path
from typing import List

__all__ = [
    "BASE_DIR",

    "HOST",
    "PORT",
    "DEBUG",
    "ALLOWED_HOST",

    "TEMPLATE_DIRS",
    "STATIC_DIRS",
    "PUBLIC_DIR",
    "MEDIA_DIR",
]

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent

# Turn off (False) for production.
DEBUG: bool = True

# Server Configuration
HOST: str = "127.0.0.1"
PORT: int = 8000
ALLOWED_HOST: List[str] = []

# Path to HTML files
TEMPLATE_DIRS: str | List[str] = "templates"  # BASE_DIR / "templates"
# Path to static folders (Directory for CSS, JS, Image, etc.)
STATIC_DIRS: List[str] = ["statics"]  # BASE_DIR / "statics"
# Path for public directory (where non-static files are located.)
PUBLIC_DIR: str = "public"
# Path where media files are stored.
MEDIA_DIR: str = "media"
```

## Examples

Check out the [example](./example) directory for sample usage and demonstrations.

## Dependencies

-   No external dependencies. Uses only Python's built-in `socket` module.

## Contribution

Contributions are welcome! Feel free to fork the repository, make improvements, and submit pull requests.

## License

This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.

## Contact

For any inquiries or support, please contact [acharyaraj.webserver@gmail.com](mailto:acharyaraj.webserver@gmail.com) or visit the [GitHub profile](https://github.com/sachin-acharya-projects/).

```bash
.
├── config/
│   ├── settings.py
│   ├── __init__.py
│   └── other_app_configurations.py
├── static/
│   ├── csses
│   └── javascripts
├── media/
│   ├── images
│   └── videos
├── public/
│   ├── logo
│   ├── robot.txt
│   └── manifest.json
├── views/
│   ├── index.html
│   └── Other HTMLs
└── main.py
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "NetJin",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "PythonFramework, WebFramework, Webserver",
    "author": null,
    "author_email": "Sachin Acharya <webserver.py.connect@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/aa/98/9c42f50e7e79bd6c95559bd0461bac84499b8206908e0b820ea8600eaafd/netjin-1.1.1.tar.gz",
    "platform": null,
    "description": "# NetJin - Simple Python Web Server Implementation\n\n## Overview\n\n`NetJin` is a lightweight web server implemented in Python using sockets. It provides a simple implementation of the HTTP protocol, allowing users to build and run web applications with ease.\n\n## Features\n\n-   **Routing**: Easily define routes for different URLs and HTTP methods.\n-   **Request Handling**: Handle incoming HTTP requests and process them accordingly.\n-   **Response Rendering**: Render HTML templates for generating dynamic content and return other responses as well.\n-   **Error Handling**: Customizable error handling for managing HTTP errors.\n\n## Installation\n\nYou can install `NetJin` using pip:\n\n```bash\npip install WebServer\n```\n\nAlternatively, you can clone or download the repository and include the `NetJin` file in your project directory.\n\n## Usage\n\n1. Import the necessary classes:\n\n    ```python\n    from WebServer import WebServer, Request, Response\n    ```\n\n2. Create an instance of the `WebServer` class:\n\n    ```python\n    app = WebServer(debug=True)\n    ```\n\n3. Define routes using the `@app.route()` decorator, specifying the URL path and supported HTTP methods. For example:\n\n    ```python\n    @app.route(\"/\", methods=[\"GET\"])\n    def home(request: Request, response: response) -> None:\n        return response.render(\"index\") # This corresponse to index.html\n    ```\n\n4. Implement functions to handle each route, receiving `Response` and `Request` objects as parameters.\n\n5. Run the server:\n\n    ```python\n    if __name__ == \"__main__\":\n        app.run()\n    ```\n\n## Settings\n\nTo configure your project, create a file named `Settings.py` in a directory named `Configurations` at the root of your project. Define the required variables as needed. For example:\n\n```python\nfrom pathlib import Path\nfrom typing import List\n\n__all__ = [\n    \"BASE_DIR\",\n\n    \"HOST\",\n    \"PORT\",\n    \"DEBUG\",\n    \"ALLOWED_HOST\",\n\n    \"TEMPLATE_DIRS\",\n    \"STATIC_DIRS\",\n    \"PUBLIC_DIR\",\n    \"MEDIA_DIR\",\n]\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent.parent.parent\n\n# Turn off (False) for production.\nDEBUG: bool = True\n\n# Server Configuration\nHOST: str = \"127.0.0.1\"\nPORT: int = 8000\nALLOWED_HOST: List[str] = []\n\n# Path to HTML files\nTEMPLATE_DIRS: str | List[str] = \"templates\"  # BASE_DIR / \"templates\"\n# Path to static folders (Directory for CSS, JS, Image, etc.)\nSTATIC_DIRS: List[str] = [\"statics\"]  # BASE_DIR / \"statics\"\n# Path for public directory (where non-static files are located.)\nPUBLIC_DIR: str = \"public\"\n# Path where media files are stored.\nMEDIA_DIR: str = \"media\"\n```\n\n## Examples\n\nCheck out the [example](./example) directory for sample usage and demonstrations.\n\n## Dependencies\n\n-   No external dependencies. Uses only Python's built-in `socket` module.\n\n## Contribution\n\nContributions are welcome! Feel free to fork the repository, make improvements, and submit pull requests.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.\n\n## Contact\n\nFor any inquiries or support, please contact [acharyaraj.webserver@gmail.com](mailto:acharyaraj.webserver@gmail.com) or visit the [GitHub profile](https://github.com/sachin-acharya-projects/).\n\n```bash\n.\n\u251c\u2500\u2500 config/\n\u2502   \u251c\u2500\u2500 settings.py\n\u2502   \u251c\u2500\u2500 __init__.py\n\u2502   \u2514\u2500\u2500 other_app_configurations.py\n\u251c\u2500\u2500 static/\n\u2502   \u251c\u2500\u2500 csses\n\u2502   \u2514\u2500\u2500 javascripts\n\u251c\u2500\u2500 media/\n\u2502   \u251c\u2500\u2500 images\n\u2502   \u2514\u2500\u2500 videos\n\u251c\u2500\u2500 public/\n\u2502   \u251c\u2500\u2500 logo\n\u2502   \u251c\u2500\u2500 robot.txt\n\u2502   \u2514\u2500\u2500 manifest.json\n\u251c\u2500\u2500 views/\n\u2502   \u251c\u2500\u2500 index.html\n\u2502   \u2514\u2500\u2500 Other HTMLs\n\u2514\u2500\u2500 main.py\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "NetJin is a lightweight web server implemented in Python using sockets. It provides a simple implementation of the HTTP protocol, allowing users to build and run web applications with ease.",
    "version": "1.1.1",
    "project_urls": {
        "Homepage": "https://github.com/sachin-acharya-projects/WebServer.py",
        "Issues": "https://github.com/sachin-acharya-projects/WebServer.py/issues"
    },
    "split_keywords": [
        "pythonframework",
        " webframework",
        " webserver"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a1598fce5af09dedf30c160b37c6083955d99b0602bf1c3356f9dc099d3d2f80",
                "md5": "c27e5131b4ed334444dc3d2731d4f650",
                "sha256": "c8329ce4750460d6a7a2d0669336f17ce47176734fe07fcadc3b8293ba5000fa"
            },
            "downloads": -1,
            "filename": "netjin-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c27e5131b4ed334444dc3d2731d4f650",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 18638,
            "upload_time": "2024-11-29T03:39:48",
            "upload_time_iso_8601": "2024-11-29T03:39:48.351311Z",
            "url": "https://files.pythonhosted.org/packages/a1/59/8fce5af09dedf30c160b37c6083955d99b0602bf1c3356f9dc099d3d2f80/netjin-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "aa989c42f50e7e79bd6c95559bd0461bac84499b8206908e0b820ea8600eaafd",
                "md5": "d2caf1d99f71c62dad7b9625cf3910ab",
                "sha256": "68d24ba52417ea7e41e98bc7e0b9930bb6bb0762af4219c5a07bbc738156a5e7"
            },
            "downloads": -1,
            "filename": "netjin-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "d2caf1d99f71c62dad7b9625cf3910ab",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 479112,
            "upload_time": "2024-11-29T03:39:49",
            "upload_time_iso_8601": "2024-11-29T03:39:49.861596Z",
            "url": "https://files.pythonhosted.org/packages/aa/98/9c42f50e7e79bd6c95559bd0461bac84499b8206908e0b820ea8600eaafd/netjin-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-29 03:39:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sachin-acharya-projects",
    "github_project": "WebServer.py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "netjin"
}
        
Elapsed time: 0.41677s