Skip to main content

Fire up your API with this flamethrower

Project description

Flama

🔥 Fire up your API with this flamethrower.

CI Status Docs Status Coverage Package version PyPI - Python Version


Documentation: https://flama.perdy.io


Flama

Flama aims to bring a layer on top of Starlette to provide an easy to learn and fast to develop approach for building highly performant GraphQL and REST APIs. In the same way of Starlette is, Flama is a perfect option for developing asynchronous and production-ready services.

Among other characteristics it provides the following:

  • Generic classes for API resources that provides standard CRUD methods over SQLAlchemy tables.
  • Schema system based on Marshmallow that allows to declare the inputs and outputs of endpoints and provides a reliable way of validate data against those schemas.
  • Dependency Injection that ease the process of managing parameters needed in endpoints. Flama ASGI objects like Request, Response, Session and so on are defined as components and ready to be injected in your endpoints.
  • Components as the base of the plugin ecosystem, allowing you to create custom or use those already defined in your endpoints, injected as parameters.
  • Auto generated API schema using OpenAPI standard. It uses the schema system of your endpoints to extract all the necessary information to generate your API Schema.
  • Auto generated docs providing a Swagger UI or ReDoc endpoint.
  • Pagination automatically handled using multiple methods such as limit and offset, page numbers...

Requirements

Installation

$ pip install flama

Example

from marshmallow import Schema, fields, validate
from flama.applications import Flama
import uvicorn

# Data Schema
class Puppy(Schema):
    id = fields.Integer()
    name = fields.String()
    age = fields.Integer(validate=validate.Range(min=0))


# Database
puppies = [
    {"id": 1, "name": "Canna", "age": 6},
    {"id": 2, "name": "Sandy", "age": 12},
]


# Application
app = Flama(
    components=[],      # Without custom components
    title="Foo",        # API title
    version="0.1",      # API version
    description="Bar",  # API description
    schema="/schema/",  # Path to expose OpenAPI schema
    docs="/docs/",      # Path to expose Swagger UI docs
    redoc="/redoc/",    # Path to expose ReDoc docs
)


# Views
@app.route("/", methods=["GET"])
def list_puppies(name: str = None) -> Puppy(many=True):
    """
    description:
        List the puppies collection. There is an optional query parameter that 
        specifies a name for filtering the collection based on it.
    responses:
        200:
            description: List puppies.
    """
    return [puppy for puppy in puppies if name in (puppy["name"], None)]
    

@app.route("/", methods=["POST"])
def create_puppy(puppy: Puppy) -> Puppy:
    """
    description:
        Create a new puppy using data validated from request body and add it 
        to the collection.
    responses:
        200:
            description: Puppy created successfully.
    """
    puppies.append(puppy)
    
    return puppy


if __name__ == '__main__':
    uvicorn.run(app, host='0.0.0.0', port=8000)

Dependencies

Following Starlette philosophy Flama reduce the number of hard dependencies to those that are used as the core:

It does not have any more hard dependencies, but some of them are necessaries to use some features:

  • pyyaml - Required for API Schema and Docs auto generation.
  • apispec - Required for API Schema and Docs auto generation.
  • python-forge - Required for pagination.
  • sqlalchemy - Required for Generic API resources.
  • databases - Required for Generic API resources.

You can install all of these with pip3 install flama[full].

Credits

That library is heavily inspired by APIStar server in an attempt to bring a good amount of it essence to work with Starlette as the ASGI framework and Marshmallow as the schema system.

Contributing

This project is absolutely open to contributions so if you have a nice idea, create an issue to let the community discuss it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flama-0.13.0.tar.gz (39.4 kB view details)

Uploaded Source

Built Distribution

flama-0.13.0-py3-none-any.whl (46.2 kB view details)

Uploaded Python 3

File details

Details for the file flama-0.13.0.tar.gz.

File metadata

  • Download URL: flama-0.13.0.tar.gz
  • Upload date:
  • Size: 39.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.8.0 Linux/5.0.0-1027-azure

File hashes

Hashes for flama-0.13.0.tar.gz
Algorithm Hash digest
SHA256 27e05a70f319bbd8b5c3f0a5bfeee1e4bc7d0c2d4ed64ae1e19f2e12344021c2
MD5 d3e8cd3c30268e060843dc641747c96a
BLAKE2b-256 6e6623c3a10b6a288f0c4e1f4ac3fa424fdaf76b219f996e047d8d6fdbaa394f

See more details on using hashes here.

File details

Details for the file flama-0.13.0-py3-none-any.whl.

File metadata

  • Download URL: flama-0.13.0-py3-none-any.whl
  • Upload date:
  • Size: 46.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.8.0 Linux/5.0.0-1027-azure

File hashes

Hashes for flama-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58d6dce54fae5d778843de8b1fe25730d01e7a84164f81086b687112bebb5efa
MD5 b036db953989bf4def19ca4293756e47
BLAKE2b-256 d2b8bb14aee3254704251a919d56b84f8527f8771dcd13212d341f4675211f58

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page