In the current digital world, micro service plays an important role in building a system that can be discussed and maintained.
This blog shows how to create Python Microservices with SQL Server To manage hotel data such as guest names, room types, check-in/check-out dates, and room numbers.
š§± Used technology piles
- Python (Flask for Microservice Framework)
- Microsoft SQL Server (Relational DB)
- SQL Server Management Studio (Admin DB)
šÆ Project Objectives
We aim to make a simple restful Python Microservice Integrated with SQL Server who do:
š ļø Steps to build Python Micro Services
1. Database settings on SQL Server
Create a new table on SQL Server to store hotel data.
SQL
Copyedit
Create a Hotel Table (
ID primary key id identity id (1,1),
Guestname Varchar (100),
Roomtype Varchar (50),
checkindate date,
Checkoutdate date,
Roomnumber Int
);
2. Python Microservice Code With Flask
This is the complete code that must be implemented Python Microservices with SQL Server:
Python
Copyedit
From Flask Import Flask, Demand, Jsonify
Import Pyodbc
App = Flask (__ Name__)
SQL Server Connection String
Conn_str = (
“Driver = {ODBC Driver 17 for SQL Server};”
“Server = Localhost \\ ‘SQLEXPRESS;” # Update with your server name
“Database = HotelDB;” # Update with your DB name
“Trusted_connection = Yes;”
)
# Create Hotel Notes
@app.route (‘/hotel’, method =[āPOSTā])
def create_hotel ():
data = request.json
Conn = pyodbc.connect (conn_str)
cursor = Conn.Cursor ()
cursor.execute (“”
Put it to the hotel (guest name, roomtype, checkindate, checkoutdate, roomnumber)
Mark (?,?,?,?,?)
“” “, Data[āguestNameā]data[āroomTypeā]data[ācheckInDateā]data[ācheckOutDateā]data[āroomNumberā])
Conn.commit ()
Conn.Close ()
Return Jsonify ({‘message’: ‘Hotel Record Made’}), 201
# Get all the hotel notes
@app.route (‘/hotel’, method =[āGETā])
Def Get_hotels ():
Conn = pyodbc.connect (conn_str)
cursor = Conn.Cursor ()
Cursor.execute (“select * from hotel”)
hotel = cursor.fetchall ()
Results = []
For lines at the hotel:
result.append ({
‘id’: row.id,
‘Guestname’: row.gestname,
‘Roomtype’: row.roomtype,
‘Checkindate’: row.checkindate.strfime (“%y-%m-%D”),
‘Checkoutdate’: row.checkoutdate.strfime (“%y-%m-%D”),
‘Roomnumber’: row.roomnumber
})
Conn.Close ()
Return jsonify (results)
# Update Hotel Notes
@app.route (‘/hotel/
def update_hotel (ID):
data = request.json
Conn = pyodbc.connect (conn_str)
cursor = Conn.Cursor ()
cursor.execute (“”
Renew the hotel
Set guestname =?, Roomtype =?, Checkindate =?, Checkoutdate =?, Roomnumber =?
Where is id =?
“” “, Data[āguestNameā]data[āroomTypeā]data[ācheckInDateā]data[ācheckOutDateā]data[āroomNumberā]identification)
Conn.commit ()
Conn.Close ()
Return Jsonify ({‘message’: ‘Updated Hotel Record’})
# Delete Hotel Notes
@app.route (‘/hotel/
def delete_hotel (ID):
Conn = pyodbc.connect (conn_str)
cursor = Conn.Cursor ()
Cursor.execute (“Delete from the hotel where id =?”, ID)
Conn.commit ()
Conn.Close ()
Return Jsonify ({‘message’: ‘Hotel Record Deleted’})
if __name__ == ‘__main__’:
app.run (debug = true)
š Test Microservice Python
Use a postman to test the end point of the fire:
- POST /Hotel ā Create a new note
- GET /Hotel ā See all notes
- PUT /Hotels/{id} ā update notes
- DELETE /hotel/{id} ā delete notes
š§ Why use Python Microservices with SQL Server?
- Scalability: Breaking Monolithic Applications into Independent Micro Services.
- Database power: SQL Server handles relational data efficiently and safely.
- Python integration: Libraries such as pyodbc make it easy to connect Python services with SQL Server.
- Easy testing: Calm architecture makes it easy to be tested and debug.
š§© Using cases in the hotel industry
- Manage orders and reservations
- Handling Check-In/Guest Check-In Operations
- Integrate the hotel system with the CRM platform
- Tracking and analysis of the availability of real time
š Conclusion
Use Python Microservices with SQL ServerYou can create a modular system, can be maintained, and can be discussed for hotel data management. This architecture allows flexibility and ensures the reliability of the company’s class. Whether you are building a hotel CRM or ordering machine, this setting is strong and ready for production.
Additional resources:
Game Center
Game News
Review Film
Berita Olahraga
Lowongan Kerja
Berita Terkini
Berita Terbaru
Berita Teknologi
Seputar Teknologi
Berita Politik
Resep Masakan
Pendidikan
Berita Terkini
Berita Terkini
Berita Terkini
review anime
Gaming Center
Originally posted 2025-08-11 16:52:43.