Schism is an autowiring library that makes modularity simple in monolithes and simplifies code sharing in microservices.
Project description
Schism
Schism is a service framework designed to simplify the process of splitting a single application into multiple services. It provides autowiring capabilities that make modularity straightforward in monolithic applications and facilitates code sharing in microservices architectures.
Installation
pip install schism
Usage
Schism is designed to have the smallest possible API surface area. You just need to create a service type that inherits from schism.Service. You can use Bevy's dependency injection to inject services into any function.
Creating a schism.config.yaml file in the root of your project will allow you to define the services that should be available in your application and how they should be exposed. Bevy then handles injecting the correct client facades into your functions so you can interact with the services as if they are still part of the same application.
To launch a service either set the SCHISM_ACTIVE_SERVICE environment variable to the name of the service to run using the schism run command. Alternatively pass the name to the schism run service command. Schism then starts the appropriate bridge servers using the configuration in the schism.config.yaml.
To run a client application that understands the running services use the schism run command. Pass it the desired module and callback (ex. module.path:callback) that you want to run (alternatively set up a launch config). Schism handles injecting the appropriate service client facades into the runtime before running the callback.
Example
Here's a basic example of a service that provides a simple greeting.
# greetings.py
from bevy import inject, dependency
from schism import Service, start_app
class GreetingService(Service):
async def greet(self, name: str) -> str:
print("Handling request...")
return f"Hello, {name}!"
@inject
async def greet(greeting_service: GreetingService = dependency()):
print(await greeting_service.greet("World"))
async def main():
await greet()
if __name__ == "__main__":
start_app(main()) # Activate a Schism controller and launch the app
Here is the corresponding schism.config.yaml file:
launch:
app: greetings:main
services:
- name: greeting
service: greetings:GreetingService
bridge:
type: schism.ext.bridges.simple_tcp:SimpleTCP
serve_on: localhost:1234
To run you must first start the greetings service with this command:
schism run service greeting
Then you can run the script and that accesses the service by passing schism.run the entry point coroutine:
schism run
Alternatively you can run it as a normal Python script with no client facades where everything runs in a single process.
python greetings.py
or
python -m greetings
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
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 schism-0.1.3.tar.gz.
File metadata
- Download URL: schism-0.1.3.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc63648e74928f87fac74a2d6a20acf403fa9135ddfea5c71120db3c1ed53b4e
|
|
| MD5 |
c5899a29b04fe4615016da10af27e058
|
|
| BLAKE2b-256 |
dcd417f848969c39e9a6f89fffeecedc0ff7911e0a225541be56a417e920f667
|
File details
Details for the file schism-0.1.3-py3-none-any.whl.
File metadata
- Download URL: schism-0.1.3-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06943c1d78bcca6b6ddd109cc134cb59ff2ffd7e725f01b5537e59e50dd87d48
|
|
| MD5 |
9662498b4880bebda563d51109aee9bd
|
|
| BLAKE2b-256 |
788abd6e20f0760876c131940994af5e4aeb3c5b78f6d5fb8bcda5b87ec716ab
|