Metadata-Version: 2.4
Name: sarva
Version: 0.1.2
Summary: Python web framework built for learning purposes.
Home-page: https://github.com/sarvar2003/sarva.git
Author: Sarvarbek Juraev
Author-email: saravarjuraev@gmail.com
License: MIT
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.6.0
Description-Content-Type: text/markdown
Requires-Dist: Jinja2==3.1.6
Requires-Dist: parse==1.21.1
Requires-Dist: requests==2.33.1
Requires-Dist: requests-wsgi-adapter==0.4.1
Requires-Dist: WebOb==1.8.9
Requires-Dist: whitenoise==6.12.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary


![alt text](<ChatGPT Image Apr 7, 2026, 08_09_07 PM-1.png>)

[![PyPI version](https://img.shields.io/pypi/v/your-package-name.svg)](https://pypi.org/project/sarva/)
[![Python Versions](https://img.shields.io/pypi/pyversions/your-package-name.svg)](https://pypi.org/sarva/quranpro/)
[![License](https://img.shields.io/pypi/l/your-package-name.svg)](https://pypi.org/project/sarva/)

# Sarva

A lightweight, fast, and minimal Python web framework built from scratch — designed to give developers full control without unnecessary complexity.

> Built for learning, performance, and flexibility.


## Overview

**Sarva** is a custom Python web framework that handles HTTP requests, routing, and responses with a clean and minimal design.

It’s created to:

* Understand how frameworks like Django and Flask work internally
* Provide a simple alternative for lightweight projects
* Give developers full control over request/response handling


## Features

*  Custom Request & Response handling
*  URL Routing system
*  Lightweight and fast
*  Minimal dependencies
*  Easy to extend
*  Uploaded to PyPi
---

## Installation
```shell
pip install sarva
```

## How to use it

### Basic Usage
```python
from sarva.api import Sarva
app = Sarva()

@app.route("/home", allowed_methods=["get"])
def home(request, response):
    response.text = "Hello from the Home Page"

@app.route("/hello/{name}")
def greeting(request, response, name):
    response.text = f"Hello {name}"

@app.route("/books")
class Books:
    def get(self, request, response):
        response.text = "Books page"
    
    def post(self, request, response):
        response.text = "Endpoint to create a book"

@app.route("/template")
def template_handler(request, response):
    response.body = app.template(
        "home.html", 
        context = {"new_title": "Best title", "new_body": "New best body"}
    )
```

### Unit tests
---

The recommended way of writing unit tests is with [pytest](https://docs.pytest.org/en/latest) . There are two built in fixtures that you may want to use when writing unit tests with Sarva. The first one is `app` which is an instance of main `API` class  

```python
def test_basic_route_adding(app):
    @app.route("/home")
    def home(request, response):
        response.text = "Hello from Home!"
```

The other one is `test_client` that you can use to send HTTP requests to your handlers.

```python
def test_parameterazied_routing(app, test_client):
    @app.route("/hello/{name}")
    def greeting(request, response, name):
        response.text = f"Hello {name}"
    
    assert test_client.get("http://testserver/hello/Sarvar").text == "Hello Sarvar"
    assert test_client.get("http://testserver/hello/John").text == "Hello John"
```

## Templates
---

The default folder for templates is `templates`. You can change that when initializing main `API()` class:
```python
app = API(templates_dir="templates_dir_name")
```
Then you can use HTML files in that folder like so in the handler:
```python
@app.route("/template")
def template_handler(request, response):
    response.body = app.template(
        "home.html", 
        context = {"new_title": "Best title", "new_body": "New best body"}
    )
```

## Static files
---

Just like templates the default folder for static files is 'static' and you can override it:

app = API(static="static_files_dir")

Then you can use file inside this folder in HTML files:

```html
<html>
<head>
    <title>{{new_title}}</title>
    <link rel="stylesheet" href="/static/home.css">
</head>
<body>
    {{new_body}}
</body>
</html>

```

## Contributing


Contributions are welcome!

Feel free to:

* Open issues
* Submit pull requests
* Suggest new features

## License


MIT License — feel free to use and modify.

## Support

If you like this project, give it a star ⭐
It helps others discover it!

## Final Note

This framework is built for learning and experimentation — but can grow into something powerful with your ideas.

