niklib.api package#

Submodules#

niklib.api.apps module#

class niklib.api.apps.StandaloneApplication(app, options=None)[source]#

Bases: BaseApplication

A runner to help us parse argparse next to gunicorn args

Note

For options, you can visit https://docs.gunicorn.org/en/latest/settings.html

__init__(app, options=None)[source]#

Initialize runner

Parameters:
  • app (Callable) – A callable as the ASGI/WSGI application

  • options (dict, optional) – A dictionary were keys are command line args and values are their corresponding values. Defaults to None.

load_config()[source]#

Loads only those options that are valid

load()[source]#

niklib.api.database module#

niklib.api.models module#

class niklib.api.models.PayloadExample(**data)[source]#

Bases: BaseModel

API payload provided by user

Validation of API payload where it has a domain specific value or has fixed data. In that case, it is expected that developer first created an interface to have access to these fixed data or domain-specific knowledge as a validator function.

sex is an example were it could be fixed, hence an enum.Enum with fixed members has been defined in niklib.data.constant.ExampleSex that contains it.

funds is a domain-specific knowledge that in this example, cannot be negative. or in some cases it could not surpass a specific value. For this, developer can add this manually here (not recommended) or creates an validator in where data actually has been first processed (e.g. niklib.data.preprocessor).

Raises:
sex: str#
funds: float#
class Config[source]#

Bases: object

orm_mode = True#
_abc_impl = <_abc._abc_data object>#
model_config: ClassVar[ConfigDict] = {'orm_mode': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'funds': FieldInfo(annotation=float, required=False, default=8000.0, title='Amount of fund', description='Amount of money you are going to bring and probably spend.', metadata=[Gt(gt=1000.0)]), 'sex': FieldInfo(annotation=str, required=False, default=<enum 'ExampleSex'>)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

Module contents#