Fast, modern microservices framework for Python - Port of Moleculer.js
Project description
MoleculerPy
MoleculerPy is a fast, modern and powerful microservices framework for Python. It helps you to build efficient, reliable & scalable services. MoleculerPy provides many features for building and managing your microservices.
Website: https://moleculerpy.services
Documentation: https://moleculerpy.services/docs
What's included
- Async/await native (built on asyncio)
- Request-reply concept
- Support event driven architecture with balancing
- Built-in service registry & dynamic service discovery
- Load balanced requests & events (round-robin, random, cpu-usage, latency, sharding)
- Many fault tolerance features (Circuit Breaker, Bulkhead, Retry, Timeout, Fallback)
- Plugin/middleware system (19 built-in middlewares)
- Support Streams for large data transfer
- Service mixins
- Built-in caching solution (Memory, Redis)
- Pluggable loggers (structlog)
- Pluggable transporters (NATS, Redis, Memory)
- Pluggable parameter validator
- Multiple services on a node/server
- Master-less architecture, all nodes are equal
- Built-in metrics feature with Prometheus exporter
- Built-in tracing feature with Console exporter
- Official REPL and Channels modules
Installation
pip install moleculerpy
With optional features:
# With Redis transporter
pip install moleculerpy[redis]
# With metrics & tracing
pip install moleculerpy[metrics,tracing]
# All features
pip install moleculerpy[all]
Create your first microservice
This example shows you how to create a small service with an add action which can add two numbers and how to call it.
import asyncio
from moleculerpy import ServiceBroker, Service, action, Context
# Define a service
class MathService(Service):
name = "math"
@action
async def add(self, ctx: Context):
return ctx.params["a"] + ctx.params["b"]
async def main():
# Create a broker
broker = ServiceBroker()
# Register the service
await broker.register(MathService())
# Start the broker
await broker.start()
# Call service
result = await broker.call("math.add", {"a": 5, "b": 3})
print(f"5 + 3 = {result}")
# Stop broker
await broker.stop()
asyncio.run(main())
Command Line Interface
MoleculerPy includes a CLI that allows you to easily start a broker and load services:
moleculerpy <service_directory> [options]
CLI Options
| Option | Description | Default |
|---|---|---|
service_directory |
Path to directory containing service files | - |
--broker-id, -b |
Broker ID | node-<current_dir_name> |
--transporter, -t |
Transporter URL | nats://localhost:4222 |
--log-level, -l |
Log level | INFO |
--log-format, -f |
Log format (PLAIN, JSON) | PLAIN |
--namespace, -n |
Service namespace | default |
Example
# Start with services from the 'services' directory
moleculerpy services
# Custom broker ID and transporter
moleculerpy services -b my-broker -t nats://nats-server:4222
# Verbose logging
moleculerpy services -l DEBUG
Official modules
We have official modules for MoleculerPy:
| Module | Description |
|---|---|
| moleculerpy-repl | Interactive CLI shell for debugging and managing services |
| moleculerpy-channels | Reliable pub/sub messaging with Redis, Kafka, NATS |
Middlewares
MoleculerPy provides a powerful middleware system to extend functionality. Middlewares can hook into various stages of request, event, and lifecycle processes.
from moleculerpy.middleware import Middleware
from moleculerpy.context import Context
class LoggingMiddleware(Middleware):
async def local_action(self, next_handler, action_endpoint):
async def wrapped_handler(ctx: Context):
print(f"Before action: {action_endpoint.name}")
result = await next_handler(ctx)
print(f"After action: {action_endpoint.name}")
return result
return wrapped_handler
# Register middleware
broker = ServiceBroker(middlewares=[LoggingMiddleware()])
Available Hooks
Wrapping Hooks
local_action(next_handler, action_endpoint)- Wraps local action handlersremote_action(next_handler, action_endpoint)- Wraps remote action callslocal_event(next_handler, event_endpoint)- Wraps local event handlers
Lifecycle Hooks
broker_created(broker)- Called after broker initializationbroker_started(broker)- Called after broker startupbroker_stopped(broker)- Called after broker shutdownservice_created(service)- Called after service registrationservice_started(service)- Called after service startup
Roadmap
Current status (v0.14.7)
- Core framework with full service lifecycle
- Service versioning —
v1.users.get,v2.users.getcoexistence,$noVersionPrefix - NATS, Redis, Memory transporters
- Pluggable serializers (JSON, MsgPack) — MsgPack 2x faster on large payloads
- Balanced request/event handling via NATS queue groups (
disable_balancer=True) - 4/4 transit middleware hooks (publish, send, receive, message handler)
- 22 built-in middlewares
- 6 load balancing strategies (including Shard)
- Circuit breaker, bulkhead, retry patterns
- Prometheus metrics & Console tracing
- Streaming support
- Protocol v4 safety: version check, NodeID conflict detection
- REPL & Channels modules
- Pre-commit/push hooks (ruff, mypy, pytest) + Codecov integration
Planned features
- REST API Gateway (moleculerpy-web)
- TCP transporter with Gossip protocol
- Database adapters (moleculerpy-db)
- LRU cache
- Jaeger & Zipkin tracing exporters
- Service versioning (v1.users.get action naming)
- Kafka transporter
- AMQP transporter
- GraphQL gateway
- gRPC support
Documentation
You can find the documentation at https://moleculerpy.services/docs.
Changelog
See CHANGELOG.md.
Contributing
We welcome you to join in the development of MoleculerPy. Please read our contribution guide.
Credits
This project is based on pylecular by Alvaro Inckot, licensed under MIT License.
Inspired by Moleculer.js - the original Node.js microservices framework.
License
MoleculerPy is available under the MIT license.
Contact
Copyright (c) 2026 MoleculerPy
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file moleculerpy-0.14.7.tar.gz.
File metadata
- Download URL: moleculerpy-0.14.7.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be9a71747b6274badbda8f9a2c53afa46a566149ba3ae2b91255d515e4b3aebe
|
|
| MD5 |
8a50f8f4de65b7fd0add6366bfa63012
|
|
| BLAKE2b-256 |
cf8aba8e30a17ea21fde1a433d779bbc738c0b4e7f1dbe8da6fd884cbe184fd8
|
Provenance
The following attestation bundles were made for moleculerpy-0.14.7.tar.gz:
Publisher:
publish.yaml on MoleculerPy/moleculerpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moleculerpy-0.14.7.tar.gz -
Subject digest:
be9a71747b6274badbda8f9a2c53afa46a566149ba3ae2b91255d515e4b3aebe - Sigstore transparency entry: 1224346555
- Sigstore integration time:
-
Permalink:
MoleculerPy/moleculerpy@575abdafeb19ff598d777834cbb9a9e32aef45fd -
Branch / Tag:
refs/tags/v0.14.7 - Owner: https://github.com/MoleculerPy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@575abdafeb19ff598d777834cbb9a9e32aef45fd -
Trigger Event:
push
-
Statement type:
File details
Details for the file moleculerpy-0.14.7-py3-none-any.whl.
File metadata
- Download URL: moleculerpy-0.14.7-py3-none-any.whl
- Upload date:
- Size: 223.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39d0501f39766fc4b619e118bedda5ec203ecbe0616d06798da221a380670381
|
|
| MD5 |
7b797691218bf0a4a71aaf8c6b0c27fb
|
|
| BLAKE2b-256 |
9f08ae206f2035db8c7ff7fd3f40428dc5555325ff7e2a3ee8635e03d72b1801
|
Provenance
The following attestation bundles were made for moleculerpy-0.14.7-py3-none-any.whl:
Publisher:
publish.yaml on MoleculerPy/moleculerpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moleculerpy-0.14.7-py3-none-any.whl -
Subject digest:
39d0501f39766fc4b619e118bedda5ec203ecbe0616d06798da221a380670381 - Sigstore transparency entry: 1224346557
- Sigstore integration time:
-
Permalink:
MoleculerPy/moleculerpy@575abdafeb19ff598d777834cbb9a9e32aef45fd -
Branch / Tag:
refs/tags/v0.14.7 - Owner: https://github.com/MoleculerPy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@575abdafeb19ff598d777834cbb9a9e32aef45fd -
Trigger Event:
push
-
Statement type: