semvec/pypi-packages huggingface dataset:
fastapi-chameleon 0.1.14
Adds integration of the Chameleon template language to FastAPI.
License: MIT

# fastapi-chameleon

Adds integration of the Chameleon template language to FastAPI. If you are interested in Jinja instead, see the sister project: [github.com/AGeekInside/fastapi-jinja](https://github.com/AGeekInside/fastapi-jinja).

## Installation

Simply `pip install fastapi_chameleon`.

## Usage

This is easy to use. Just create a folder within your web app to hold the templates such as:

```
├── main.py
├── views.py
│
├── templates
│   ├── home
│   │   └── index.pt
│   └── shared
│       └── layout.pt

```

In the app startup, tell the library about the folder you wish to use:

```python
import os
from pathlib import Path
import fastapi_chameleon

dev_mode = True

BASE_DIR = Path(__file__).resolve().parent
template_folder = str(BASE_DIR / 'templates')
fastapi_chameleon.global_init(template_folder, auto_reload=dev_mode)
```

Then just decorate the FastAPI view methods (works on sync and async methods):

```python
@router.post('/')
@fastapi_chameleon.template('home/index.pt')
async def home_post(request: Request):
    form = await request.form()
    vm = PersonViewModel(**form) 

    return vm.dict() # {'first':'Michael', 'last':'Kennedy', ...}

```

The view method should return a `dict` to be passed as variables/values to the template. 

If a `fastapi.Response` is returned, the template is skipped and the response along with status_code and
other values is directly passed through. This is common for redirects and error responses not meant
for this page template.

## Friendly 404s and errors

A common technique for user-friendly sites is to use a 
[custom HTML page for 404 responses](http://www.instantshift.com/2019/10/16/user-friendly-404-pages/).
This is especially important in FastAPI because FastAPI returns a 404 response + JSON by default.
This library has support for friendly 404 pages using the `fastapi_chameleon.not_found()` function.

Here's an example:

```python
@router.get('/catalog/item/{item_id}')
@fastapi_chameleon.template('catalog/item.pt')
async def item(item_id: int):
    item = service.get_item_by_id(item_id)
    if not item:
        fastapi_chameleon.not_found()
    
    return item.dict()
```

This will render a 404 response with using the template file `templates/errors/404.pt`.
You can specify another template to use for the response, but it's not required.

If you need to return errors other than `Not Found` (status code `404`), you can use a more
generic function: `fastapi_chameleon.generic_error(template_file: str, status_code: int)`.
This function will allow you to return different status codes. It's generic, thus you'll have
to pass a path to your error template file as well as a status code you want the user to get
in response. For example:

```python
@router.get('/catalog/item/{item_id}')
@fastapi_chameleon.template('catalog/item.pt')
async def item(item_id: int):
    item = service.get_item_by_id(item_id)
    if not item:
        fastapi_chameleon.generic_error('errors/unauthorized.pt',
                                        fastapi.status.HTTP_401_UNAUTHORIZED)

    return item.dict()
```
bulk-cli 0.1.0
Bulk helps you declare, manage and install dependencies of Python projects.
License: MIT
Requires Python: >=3.11,<4.0

# bulk
Bulk helps you declare, manage and install dependencies of Python projects.

# Installations
install bulk on python using pip

```shell
    pip install bulk-cli
```

# Bulk commands
```shell
    bulk init
```

init bulk config in a project 
if you have an old project using pip use the flag
``--ancestor=pip`` ( Not necessary if you have requirements.txt in your project)

```shell
bulk install
```

If you have requirements.txt file in your project bulk will add all packages from it to bulk.dependencies 

```shell
bulk install package-name
```

Install a package from pip library

```shell
bulk install --dry
```
Create bulk config from pip packages without installing

```shell
bulk uninstall
```
Uninstall project dependencies

```shell
bulk uninstall package-name
```

Uninstall a package from pip library


```shell
bulk run ...
```

Bulk allows you to run multiple commands one 

```json
    {
        "script": {
            "dev": "python manage.py makemigrations && python manage.py migrate && python manage.py runserver"
        }
    }
```

Note: replace && with ; if you are using windows
run dev 
```shell
    bulk run dev
```

# Documentation
Documentation for the current version of Bulk  is available from github README.


[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/lyonkvalid)