Skip to main content

FastMicro

Fast, simple microservice framework

Test Coverage Package version


FastMicro is a modern, fast (high-performance) framework for building microservices with Python 3.7+ based on asyncio.

Install

To install FastMicro run the following:

$ pip install fastmicro[redis]

Example

This example shows how to use the default in-memory backend for evaluation and testing.

Note:

The in-memory backend cannot be used for inter-process communication.

Create it

  • Create a file hello.py with:
#!/usr/bin/env python3

import asyncio
from pydantic import BaseModel

from fastmicro.messaging.memory import Messaging
from fastmicro.service import Service


class User(BaseModel):
    name: str


class Greeting(BaseModel):
    name: str
    greeting: str


service = Service("test")
loop = asyncio.get_event_loop()
messaging = Messaging(loop=loop)
user_topic = messaging.topic("user", User)
greeting_topic = messaging.topic("greeting", Greeting)


@service.entrypoint(user_topic, greeting_topic)
async def greet(user: User) -> Greeting:
    greeting = Greeting(name=user.name, greeting=f"Hello, {user.name}!")
    return greeting


async def main() -> None:
    await service.start()

    async with messaging:
        user = User(name="Greg")
        print(user)
        greeting = await service.greet(user)
        print(greeting)

    await service.stop()


if __name__ == "__main__":
    loop.run_until_complete(main())

Run it

$ python hello.py
{'name': 'Greg'}
{'name': 'Greg', 'greeting': 'Hello, Greg!'}

Backends

FastMicro supports the following backends:

To install FastMicro with one of these backends run one of the following:

$ pip install fastmicro[kafka]
$ pip install fastmicro[redis]

Another Example

This example shows how to use the Redis backend for inter-process communication.

Create it

  • Create a file example.py with:
#!/usr/bin/env python3

import asyncio
from pydantic import BaseModel

from fastmicro.messaging.redis import Messaging
from fastmicro.service import Service


class User(BaseModel):
    name: str


class Greeting(BaseModel):
    name: str
    greeting: str


service = Service("test")
loop = asyncio.get_event_loop()
messaging = Messaging(loop=loop)
user_topic = messaging.topic("user", User)
greeting_topic = messaging.topic("greeting", Greeting)


@service.entrypoint(user_topic, greeting_topic)
async def greet(user: User) -> Greeting:
    print(user)
    greeting = Greeting(name=user.name, greeting=f"Hello, {user.name}!")
    print(greeting)
    return greeting


if __name__ == "__main__":
    service.run()
  • Create a file test.py with:
#!/usr/bin/env python3

import asyncio
from pydantic import BaseModel

from fastmicro.messaging.redis import Messaging
from fastmicro.service import Service


class User(BaseModel):
    name: str


class Greeting(BaseModel):
    name: str
    greeting: str


service = Service("test")
loop = asyncio.get_event_loop()
messaging = Messaging(loop=loop)
user_topic = messaging.topic("user", User)
greeting_topic = messaging.topic("greeting", Greeting)


@service.entrypoint(user_topic, greeting_topic)
async def greet(user: User) -> Greeting:
    ...


async def main() -> None:
    async with messaging:
        user = User(name="Greg")
        print(user)
        greeting = await service.greet(user)
        print(greeting)


if __name__ == "__main__":
    loop.run_until_complete(main())

Run it

  • In a terminal run:
$ python example.py
{'name': 'Greg'}
{'name': 'Greg', 'greeting': 'Hello, Greg!'}
^C
  • In another terminal run:
$ python test.py
{'name': 'Greg'}
{'name': 'Greg', 'greeting': 'Hello, Greg!'}

License

This project is licensed under the terms of the MIT license.

Metadata

Release files for fastmicro 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastmicro 0.3.2
File Size Uploaded Provenance Actions
fastmicro-0.3.2.tar.gz 11.2 kB Without provenance Details for fastmicro-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastmicro 0.3.2
File Interpreter ABI Platform Actions
fastmicro-0.3.2-py3-none-any.whl Python 3 none any Details for fastmicro-0.3.2-py3-none-any.whl

Total release size: 25.8 kB

Release files / fastmicro-0.3.2.tar.gz

Download URL fastmicro-0.3.2.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d0bb8481e8a564ce3f5e66e238fa92f6b757c7e85b027071b5a039bcede3eedc
BLAKE2b-256 checksum
How to use checksums
016cba848a2ad7076bb31636ac1fe0e1a3e31bf4ee18ccb275f01ea97e150625
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.8.10 Linux/5.4.0-91-generic

Release files / fastmicro-0.3.2-py3-none-any.whl

Download URL fastmicro-0.3.2-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cafc4c23bd80e805b9aea14e3905152ee14934796b9a6d657fbb73d488119399
BLAKE2b-256 checksum
How to use checksums
a3acf94ea5f8ad67d62e2b3118777e25cf68281ce667fc6d82cb82f9e60c7009
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.8.10 Linux/5.4.0-91-generic

Security for fastmicro 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page