Flaxon Spring-Boot
Spring Boot-style patterns for Flaxon — Dependency Injection, AOP, REST Controllers, and more.
Table of Contents
What is this?
Flaxon Spring-Boot brings the battle-tested patterns of Spring Boot to Python. It provides:
- 🔄 Dependency Injection —
@Autowired,@Component,@Service,@Repository - 🎯 AOP (Aspect-Oriented) —
@Aspect,@Before,@After,@Around - 🚀 Auto-Configuration — Auto-detect and configure components
- 📝 Application Properties —
application.yml/application.propertiessupport - 🎭 Profiles —
@Profile("dev"),@Profile("prod")environment-specific beans - ⏰ Scheduled Tasks —
@Scheduled(cron="* * * * *") - 💾 Transactional —
@Transactionalfor database operations - 🌐 REST Controllers —
@RestController,@GetMapping,@PostMapping - 📊 Spring Data JPA-style — Repository interfaces with auto-CRUD
- 📈 Actuator — Health checks, metrics, info endpoints
- 📡 Event Listeners —
@EventListenerfor application events - ⚙️ Configuration Properties —
@ConfigurationPropertiesfor typed config
Why Spring Boot Patterns in Python?
| Problem | Solution |
|---|---|
| Manual dependency wiring | @Autowired auto-wiring |
| Boilerplate CRUD code | @Repository + auto-CRUD |
| Transaction boilerplate | @Transactional |
| Manual scheduling setup | @Scheduled cron/fixed-delay |
| Cross-cutting concerns scattered | @Aspect AOP |
| Hard-coded configuration | application.yml profiles |
| No built-in health checks | /actuator/health, /actuator/metrics |
Installation
pip install flaxon-spring-boot
With dev dependencies:
pip install flaxon-spring-boot[dev]
Quick Start
1. Load the Plugin
from flaxon import Flaxon
from flaxon_spring_boot import SpringBootPlugin
app = Flaxon("my-app")
# Load Spring Boot plugin
app.plugins.load_plugin(SpringBootPlugin(
profiles=["dev"],
autoconfigure=True,
actuator_enabled=True,
))
2. Create a Service
from flaxon_spring_boot import Service, Autowired, Repository
@Service
class UserService:
@Autowired
def __init__(self, repo: UserRepository):
self.repo = repo
async def get_user(self, id: int):
return await self.repo.find_by_id(id)
@Repository
class UserRepository:
_data = {}
async def find_by_id(self, id: int):
return self._data.get(id)
async def save(self, data: dict):
self._data[data["id"]] = data
return data
3. Create a REST Controller
from flaxon_spring_boot import RestController, GetMapping, PostMapping, RequestBody
@RestController("/api/users")
class UserController:
@Autowired
def __init__(self, service: UserService):
self.service = service
@GetMapping("/{id}")
async def get_user(self, id: int):
return await self.service.get_user(id)
@PostMapping
async def create_user(self, @RequestBody data: dict):
return await self.service.create_user(data)
4. Run the App
flaxon run app:app --reload
Features
Dependency Injection
from flaxon_spring_boot import Component, Autowired, Service
@Component
class DatabaseConfig:
def __init__(self):
self.url = "postgresql://localhost:5432/mydb"
@Service
class UserService:
@Autowired
def __init__(self, config: DatabaseConfig, repo: UserRepository):
self.config = config
self.repo = repo
AOP (Aspect-Oriented Programming)
from flaxon_spring_boot import Aspect, Before, After, Pointcut
@Aspect
class LoggingAspect:
@Pointcut("execution(* UserService.*(..))")
def service_methods(self):
pass
@Before("service_methods")
def log_before(self, join_point):
print(f"Calling: {join_point.method}")
@After("service_methods")
def log_after(self, join_point, result):
print(f"Returned: {result}")
Scheduled Tasks
from flaxon_spring_boot import Scheduled, Component
@Component
class ReportScheduler:
@Scheduled(cron="0 0 * * * *") # Every hour
async def generate_report(self):
await report_service.generate()
@Scheduled(fixed_delay=5000) # Every 5 seconds
async def ping_health(self):
print("Health check")
Transactional
from flaxon_spring_boot import Transactional, Service
@Service
class OrderService:
@Transactional
async def create_order(self, order_data):
# Auto-rollback on exception
order = await order_repo.save(order_data)
await inventory_repo.update(order.items)
return order
Application Properties
# application.yml
spring:
datasource:
url: postgresql://localhost:5432/mydb
username: admin
password: secret
app:
name: My Flaxon App
version: 1.0.0
logging:
level: DEBUG
from flaxon_spring_boot import ConfigurationProperties
@ConfigurationProperties("app")
class AppConfig:
name: str
version: str
Actuator Endpoints
| Endpoint | Purpose |
|---|---|
/actuator/health |
Application health status |
/actuator/info |
Application information |
/actuator/metrics |
Performance metrics |
/actuator/routes |
Registered routes |
/actuator/beans |
Managed beans |
Profiles
from flaxon_spring_boot import Profile, Component
@Component
@Profile("dev")
class DevDatabaseConfig:
url = "postgresql://localhost:5432/dev"
@Component
@Profile("prod")
class ProdDatabaseConfig:
url = "postgresql://production:5432/prod"
File Structure
Spring vs Flaxon Spring-Boot
| Spring (Java) | Flaxon Spring-Boot (Python) |
|---|---|
@Autowired |
@Autowired |
@Service |
@Service |
@Repository |
@Repository |
@RestController |
@RestController |
@GetMapping |
@GetMapping |
@Transactional |
@Transactional |
@Scheduled |
@Scheduled |
@Aspect |
@Aspect |
application.properties |
application.yml |
@Profile |
@Profile |
| Spring Boot Actuator | Flaxon Actuator |
@EventListener |
@EventListener |
@ConfigurationProperties |
@ConfigurationProperties |
Requirements
Python 3.11+
Flaxon 0.1.9+
License
MIT License - See LICENSE file for details.
Support
📚 Documentation
🐛 Issue Tracker
💬 Discussions
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 flaxon_spring_boot-0.1.1.tar.gz.
File metadata
- Download URL: flaxon_spring_boot-0.1.1.tar.gz
- Upload date:
- Size: 33.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd58c6622cf93e1448a2cbdfd54d77b8880743daf6d807e7ffd0df98b05f9cdf
|
|
| MD5 |
d0654ed48ccaed305f3077a8ceda7f2f
|
|
| BLAKE2b-256 |
df4bdff6c60be233efd30304fca05927a5da5fa9ba1fb45fdd25ef19a8cc2a65
|
File details
Details for the file flaxon_spring_boot-0.1.1-py3-none-any.whl.
File metadata
- Download URL: flaxon_spring_boot-0.1.1-py3-none-any.whl
- Upload date:
- Size: 33.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a508abd9c49727db5e0bcdf2dd2b85d574a7a2bc39b703e9ab97f2d675fdaa39
|
|
| MD5 |
f890883860c3aee90f2aac49c3af9882
|
|
| BLAKE2b-256 |
c8fce6762ac032f34a97e4fd22698174a1cc9a66de6d6164bc83313a79574b60
|