Skip to main content

UtilMeta - progressive meta framework for API development in Python

Project description

UtilMeta Python Framework

UtilMeta Python framework is a progressive meta-framework to develop and manage backend applications, building declarative API & ORM efficiently based on the Python type annotation standard with both sync & async syntax, and supports using mainstream Python frameworks as runtime backend

Installation

pip install utilmeta

UtilMeta requires Python >= 3.8

Core Features

Declarative API & ORM

with UtilMeta, you can easily write declarative APIs with auto request validation, efficient ORM queries, and auto OpenAPI document generation, here is an example from mini_blog/blog/api.py

from utilmeta.core import api, orm
from .models import User, Article
from django.db import models

class UserSchema(orm.Schema[User]):
    username: str
    articles_num: int = models.Count('articles')

class ArticleSchema(orm.Schema[Article]):
    id: int
    author: UserSchema
    content: str

class ArticleAPI(api.API):
    async def get(self, id: int) -> ArticleSchema:
        return await ArticleSchema.ainit(id)

if you request the ArticleAPI like GET /article?id=1, you will get the result like

{
  "id": 1,
  "author": {
    "username": "alice",
    "articles_num": 3
  },
  "content": "hello world"
}

This is just what you declared, UtilMeta will generate optimized ORM queries automatically based on your declared schemas, prevent N+1 problem and also generate OpenAPI document for your APIs

Progressive Meta Framework

UtilMeta built a standard that support most major Python web frameworks as runtime backend, and support current projects using these frameworks to develop new API using UtilMeta progressively

Currently supported backends:

  • Django (also Django REST framework)
  • Flask (also APIFlask)
  • FastAPI (also Starlette)
  • Sanic
  • Tornado

You can change the entire runtime backend with a single line of code, Here is a hello world example of UtilMeta

from utilmeta import UtilMeta
from utilmeta.core import api
import django

class RootAPI(api.API):
    @api.get
    def hello(self):
        return 'world'

service = UtilMeta(
    __name__,
    name='demo',
    backend=django,    # or flask / fastapi / starlette / sanic / tornado
    api=RootAPI,
    route='/api'
)

app = service.application()  # wsgi app

if __name__ == '__main__':
    service.run()

You can create a Python file with the above code and run it to check it out.

Quick Start

you can start by easily start by clone out repo and run an example

pip install -U utilmeta
git clone https://github.com/utilmeta/utilmeta-py
cd utilmeta-py/examples/mini_blog
meta migrate        # migrate databases
meta run            # or python server.py

The following info Implies that the service has live

| UtilMeta (version) starting service [blog]
|     version: 0.1.0
|       stage: ● debug
|     backend: fastapi (version) | asynchronous
|    base url: http://127.0.0.1:8080

Connect

When you started your service, you can see a line of output

UtilMeta OperationsAPI loaded at http://127.0.0.1:8080/ops, connect your APIs at https://ops.utilmeta.com

this indicates that UtilMeta Operations system is loaded successfully, you You can connect your APIs by open this link: https://ops.utilmeta.com/localhost?local_node=http://127.0.0.1:8080/ops

Click API and your will see the generated API document, you can debug your API here With your local API connected, you can use these features

  • Data: Manage database data (CRUD), in this example, you can add user and article instance
  • API: view and debug on auto generated API document
  • Logs: query realtime request logs, view request and response data, error tracebacks
  • Servers: view realtime metrics of service resources like servers, databases, caches

Using other management features requires you to connect a online service with public network address

Document Guide

We have several introductory case tutorials from easy to complex, covering most usage of the framework. You can read and learn in the following order.

  1. BMI Calculation API
  2. User Login & RESTful API
  3. Realworld Blog Project
  4. Websocket Chatroom (coming soon)

If you prefer to learn from a specific feature, you can refer to

  • Handle Request: How to handle path, query parameters, request body, file upload, request headers and cookies.
  • API Class and Routing How to use API class mounts to define tree-like API routing, and use hooks to easily reuse code between APIs, handle errors, and template responses.
  • Schema Query and ORM How to use UtilMeta to write declarative ORM queries for RESTful API.
  • API Authentication: How to use Session, JWT, OAuth and other methods to authenticate the request of the interface, get the current request's user and simplify the login operation
  • Declarative Web Client: Use the declarative syntax identical to API to write request client code, and genrate client code based on UtilMeta service or OpenAPI docs

If your APIs are developed, and want to know how to config, run and manage your APis, check

  • Config, Run & Deploy: How to configure the run settings, startup, and deployment of a service using features such as declarative environment variables
  • Connect & Operations: How to connect and manage your API service

Community

Join our community to build great things together

Enterprise Solutions & Support

The UtilMeta team is providing custom solutions and enterprise-level support at

You can also contact us in this page

Wechat

Contact the creator's wechat (voidZXL) for support or join the developers wechat group

drawing

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

utilmeta-2.6.3.tar.gz (311.3 kB view details)

Uploaded Source

Built Distribution

utilmeta-2.6.3-py3-none-any.whl (411.5 kB view details)

Uploaded Python 3

File details

Details for the file utilmeta-2.6.3.tar.gz.

File metadata

  • Download URL: utilmeta-2.6.3.tar.gz
  • Upload date:
  • Size: 311.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for utilmeta-2.6.3.tar.gz
Algorithm Hash digest
SHA256 7c68c22f33546663f41c94d5959ac8e0915f6de37a193d9314cc59b04e9a486c
MD5 e698c874406cb55e3c5a360c0d57e864
BLAKE2b-256 2e7aa4d641565f059d4370b03f0fea4d096e5c889b09fa0da9345096c5c4025c

See more details on using hashes here.

File details

Details for the file utilmeta-2.6.3-py3-none-any.whl.

File metadata

  • Download URL: utilmeta-2.6.3-py3-none-any.whl
  • Upload date:
  • Size: 411.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for utilmeta-2.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 270ee99fd6202240157d52c5f7b2abc921d30d991c7928336a5361409115fb85
MD5 bacd89405e0020ee1e162c853a5423a8
BLAKE2b-256 b88cc8e445beec1530ef8150d949d3cac73328316f1b132a956129bcd544582c

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