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.1.0.tar.gz (76.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pokie-1.1.0-py3-none-any.whl (115.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pokie-1.1.0.tar.gz
Algorithm Hash digest
SHA256 5b7261d375a2c0aa17b6f67440779b19810c1b3a9d07b4ae4b32f031cace7f37
MD5 d8ec76525cbedf5a593e2256c6a0e8e3
BLAKE2b-256 7c273d8301367f464d72a01f418c28ab2ae8d2ed5595f4c402384a69d9e52b6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pokie-1.1.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.

File details

Details for the file pokie-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pokie-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 115.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pokie-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad881530399136d7a18e6a8ad407682b09b460e659c2110474f23ad8279da10e
MD5 a716012ec2fff8dd6c7de6be5896729f
BLAKE2b-256 0ed6637ccc9474408d079857fdccb69fbb637b34c7aee8d356990e4a7a319479

See more details on using hashes here.

Provenance

The following attestation bundles were made for pokie-1.1.0-py3-none-any.whl:

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