Skip to main content

A high-level Python REST web framework based on Flask, Rick and RickDb.

Project description

Welcome to Pokie

Tests pypi license

Pokie is an REST web framework built on top of Flask, Rick and Rick-db libraries, following three-layer and clean architecture design principles.

It features an object-oriented design, borrowing from common patterns found in other languages, such as dependency injection, service location, factories and object composition. It also offers the following functionality:

  • Modular design;
  • Dependency registry and factories;
  • Configuration via environment variables or JSON files;
  • CLI command support;
  • Events and signal handlers;
  • Caching (Redis, in-memory, dummy);
  • Jobs with per-job intervals, retry/backoff, and timeouts;
  • CORS and rate limiting via built-in factories;
  • OpenAPI 3.0 spec generation from registered routes;
  • Fixtures;
  • Unit testing support with pytest;
  • Code generation;
  • Automatic REST endpoint generation;
  • REST-oriented service design;
  • Compatibility with Flask;
  • Forward-only SQL migrations;
  • PostgreSQL support;

For detailed information, please check the Documentation

Automatic REST from Database Tables

Generate full CRUD endpoints directly from a database table — no DTO, no RequestRecord, no service class needed:

from pokie.core import BaseModule
from pokie.http import AutoRouter
from pokie.rest.auto import Auto


class Module(BaseModule):
    name = "my_module"

    def build(self, parent=None):
        app = parent.app

        # generate a full REST view from the "customers" table
        view = Auto.view(app, "customers")
        AutoRouter.resource(app, "customer", view, id_type="string")

This introspects the customers table at startup and registers:

URL Method Operation
/customer GET List records
/customer/<string:id_record> GET Get by id
/customer POST Create
/customer/<string:id_record> PUT, PATCH Update
/customer/<string:id_record> DELETE Delete

Listing supports server-side pagination, sorting, filtering and free-text search out of the box via query parameters (offset, limit, sort, match, search).

Automatic REST from DTO Records

For more control, use Auto.rest() with a DTO Record — Pokie generates the RequestRecord and service automatically:

from rick_db import fieldmapper
from pokie.core import BaseModule
from pokie.rest.auto import Auto


@fieldmapper(tablename="customers", pk="customer_id")
class CustomerRecord:
    id = "customer_id"
    company_name = "company_name"
    contact_name = "contact_name"


class Module(BaseModule):
    name = "my_module"

    def build(self, parent=None):
        Auto.rest(
            parent.app,
            "customer",
            CustomerRecord,
            search_fields=[CustomerRecord.company_name, CustomerRecord.contact_name],
            id_type="string",
        )

Both approaches can be incrementally customized — add a custom RequestRecord for input validation, a custom service for business logic, or a custom base class for authentication.

Getting Started

  1. Create the application entrypoint, called main.py:
from rick.resource.config import EnvironmentConfig
from pokie.config import PokieConfig
from pokie.core import FlaskApplication
from pokie.core.factories.pgsql import PgSqlFactory


class Config(EnvironmentConfig, PokieConfig):
    pass


def build_pokie():
    cfg = Config().build()

    modules = [
        # add your modules here
    ]

    factories = [
        PgSqlFactory,
    ]

    pokie_app = FlaskApplication(cfg)
    flask_app = pokie_app.build(modules, factories)
    return pokie_app, flask_app


main, app = build_pokie()

if __name__ == '__main__':
    main.cli()
  1. Scaffold a module:
$ python3 main.py codegen:module my_module_name .
  1. Add the module to the module list on main.py:
    modules = [
        'my_module_name',
    ]
  1. Implement the desired logic in the module

Running tests with tox

  1. Install tox & tox-docker:
$ pip install -r requirements-test.txt
  1. Run tests:
$ tox [-e py<XX>]

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

pokie-1.0.0.tar.gz (75.0 kB view details)

Uploaded Source

File details

Details for the file pokie-1.0.0.tar.gz.

File metadata

  • Download URL: pokie-1.0.0.tar.gz
  • Upload date:
  • Size: 75.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pokie-1.0.0.tar.gz
Algorithm Hash digest
SHA256 05b8e3b85a4e29208e57750f70a06b276539934d60f091971eb63de6c14c372e
MD5 7c4573df7298cdcc8ff8b867e7f79771
BLAKE2b-256 2abce0ee22ae18ec18be1ecbd96c31d814a6d076b3f8be1dcea89db2b13362dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pokie-1.0.0.tar.gz:

Publisher: publish.yml on oddbit-project/pokie

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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