Connect FastAPI microservices easily.
Project description
Install
pip install fastmicroservices
Usage
import time
from toomanythreads import ThreadedServer
from fastmicroservices import Macroservice
from fastmicroservices import Microservice
class Dummy(ThreadedServer, Microservice):
def __init__(self, macroservice: Macroservice):
ThreadedServer.__init__(self)
Microservice.__init__(self, macroservice)
@self.get("/")
def foobar():
return "foobar"
if __name__ == "__main__":
m = Macroservice()
serv = Dummy(m)
m.thread.start()
time.sleep(100)
How it works
The core routing engine uses /page/{page_name}/{path:path}:
- Automatic Directory Construction: The backend uses TooManyConfigs and FastJ2 to automatically provision a templates folder and render from it.
- Service Discovery: Macroservice finds your service by
page_name, which is the lowercase class' name. In the above instance, it would be http://localhost:{port}/page/dummy - Internal Routing: Your service handles its own routes via the
forward()method. You can code your own forwarding method, but ThreadedServer already provides this. See https://pypi.org/project/toomanythreads/
Example: /page/dummy/api/users → finds "dummy" service → calls dummy.forward("/api/users")
Static HTML files in templates/static_pages/ work the same way but just render templates.
Licensed under MIT.
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 fastmicroservices-0.1.46.tar.gz.
File metadata
- Download URL: fastmicroservices-0.1.46.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.2 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c6b06288f4d2a06efefad3b62101cc4dc86e71f2411cd6707f854841a385d66
|
|
| MD5 |
2ebf9fe30dc081108344a58efe90fb0f
|
|
| BLAKE2b-256 |
7b88cbbb91a212a6dfdd3ad6f8e09cb310185a6c3bcdae540df6e5b07c2d7f71
|
File details
Details for the file fastmicroservices-0.1.46-py3-none-any.whl.
File metadata
- Download URL: fastmicroservices-0.1.46-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.2 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ada91e711d4f28f77a088e36fb4c017297ab2630ce1474f33b4d626479f6ddc
|
|
| MD5 |
dd6ffd4306e0d5bd0c16e1ce62011f98
|
|
| BLAKE2b-256 |
ec0826462849941699d3fcf518ff53e3bdb916644f1c83e005869cd6a7f641e3
|