logo

Building TMF-Compliant APIs with FastAPI: A Step-by-Step Comparison

VH CHAUDHARY
Building TMF-Compliant APIs with FastAPI: A Step-by-Step Comparison

FastAPI has gained immense popularity due to its speed, ease of use, and automatic OpenAPI documentation generation. However, in the telecommunications sector, APIs need to follow the TM Forum (TMF) standards to ensure interoperability across different service providers. This blog explores the differences between a normal FastAPI implementation and a TMF-compliant FastAPI, providing an in-depth comparison, tested code examples, and insights into how Pysquad can help you implement TMF-compliant solutions.

Comparison: Normal FastAPI vs. TMF-Compliant FastAPI

The core difference lies in standardization. TMF-compliant FastAPI implementations must follow TMF Open API guidelines, ensuring that APIs integrate seamlessly across telecom services.

Example: Normal FastAPI vs. TMF-Compliant FastAPI

Below are two implementations showcasing the differences:

Normal FastAPI Example

A standard FastAPI application with a simple Product Catalog API.

from fastapi import FastAPI
from pydantic import BaseModel
from typing import List

app = FastAPI()

# Product model
class Product(BaseModel):
    id: int
    name: str
    price: float
    description: str

# Sample product data
products = [
    Product(id=1, name="Product A", price=99.99, description="Standard product"),
    Product(id=2, name="Product B", price=149.99, description="Premium product"),
]

@app.get("/products", response_model=List[Product])
def get_products():
    return products

@app.get("/products/{product_id}", response_model=Product)
def get_product(product_id: int):
    for product in products:
        if product.id == product_id:
            return product
    return {"error": "Product not found"}

@app.post("/products", response_model=Product)
def create_product(product: Product):
    products.append(product)
    return product

Limitations (Not TMF-Compliant):

❌ Uses custom API paths (/products) instead of TMF’s /productCatalogManagement/v4/productOffering
❌ Lacks TMF-compliant request/response models
❌ No TMF-defined attributes like @type@baseType@schemaLocationlastUpdate
❌ Lacks TMF OpenAPI compatibility

TMF-Compliant FastAPI Implementation

This follows TMF620 Product Catalog API specifications.

from fastapi import FastAPI
from pydantic import BaseModel, HttpUrl
from typing import List, Optional
from datetime import datetime

app = FastAPI()

# TMF 620 Product Offering Model
class ProductOffering(BaseModel):
    id: str
    name: str
    description: Optional[str] = None
    version: Optional[str] = "1.0"
    lastUpdate: datetime
    lifecycleStatus: str
    isBundle: bool
    price: float
    @type: str = "ProductOffering"
    @baseType: str = "Entity"
    @schemaLocation: Optional[HttpUrl] = "https://example.com/schema/ProductOffering"

# Sample TMF-compliant data
product_offerings = [
    ProductOffering(
        id="1",
        name="TMF Product A",
        description="TMF Compliant product",
        lastUpdate=datetime.utcnow(),
        lifecycleStatus="Active",
        isBundle=False,
        price=99.99,
    )
]

@app.get("/productCatalogManagement/v4/productOffering", response_model=List[ProductOffering])
def get_product_offerings():
    return product_offerings

@app.get("/productCatalogManagement/v4/productOffering/{product_id}", response_model=ProductOffering)
def get_product_offering(product_id: str):
    for product in product_offerings:
        if product.id == product_id:
            return product
    return {"error": "Product Offering not found"}

@app.post("/productCatalogManagement/v4/productOffering", response_model=ProductOffering)
def create_product_offering(product: ProductOffering):
    product_offerings.append(product)
    return product

✅ TMF Compliance in This Version:

✔ Uses TMF620-compliant endpoint paths (/productCatalogManagement/v4/productOffering)
✔ Implements TMF attributes (@type@baseType@schemaLocationlastUpdate)
✔ Uses lifecycleStatus (ActiveInactiveDeprecated, etc.)
✔ Follows TMF-defined API contracts for OpenAPI and REST

Pros of TMF-Compliant FastAPI

  1. Interoperability: Ensures seamless integration with telecom services and vendors.
  2. Standardized Data Models: Uses predefined schemas, reducing inconsistencies.
  3. Improved Error Handling: TMF mandates specific error responses, making debugging easier.
  4. Better Documentation: TMF-compliant APIs follow structured OpenAPI documentation.
  5. Security: Adheres to industry-standard authentication methods.
  6. Future-Proofing: Aligns with industry standards, ensuring long-term usability.

How Pysquad Can Assist in Implementation

Pysquad has deep expertise in building TMF-compliant APIs using FastAPI. Whether developing a telecom service or integrating with existing TMF solutions, Pysquad ensures your API meets industry standards.

Here’s how Pysquad can help:

  1. TMF API Consultation: Our experts analyze your requirements and align them with TMF Open API standards.
  2. FastAPI DevelopmentPysquad builds robust, high-performance FastAPI applications with TMF compliance.
  3. Schema Validation: We implement TMF-defined data models to ensure seamless interoperability.
  4. Security CompliancePysquad ensures authentication and authorization meet TMF security guidelines.
  5. Performance Optimization: We optimize your FastAPI application for low latency and high scalability.
  6. Automated TestingPysquad integrates CI/CD pipelines with automated testing to maintain quality.
  7. API Gateway & Monitoring: We set up API gateways and monitoring tools for enhanced security and observability.
  8. Error Handling Best PracticesPysquad implements TMF-compliant error handling mechanisms.
  9. End-to-End DeploymentPysquad ensures a smooth transition from development to cloud deployment.
  10. Ongoing Support & MaintenancePysquad provides long-term support for API enhancements and compliance updates.

References

  1. TM Forum Open APIs
  2. FastAPI Documentation
  3. TMF API Security Guidelines

Conclusion

While a normal FastAPI implementation is flexible and fast, TMF-compliant FastAPI ensures industry-standard interoperability, security, and documentation. For telecom applications, following TMF guidelines is essential for seamless integration and compliance. Pysquad specializes in helping businesses implement TMF-compliant APIs, ensuring efficient and secure API development. By leveraging Pysquad’s expertise, companies can effortlessly deploy robust, scalable, and TMF-compliant FastAPI solutions.

For businesses looking to adopt TMF-compliant APIs, partnering with Pysquad guarantees expert guidance and seamless implementation. Get in touch with Pysquad today to streamline your FastAPI development journey!

About PySquad

PySquad works with businesses that have outgrown simple tools. We design and build digital operations systems for marketplace, marina, logistics, aviation, ERP-driven, and regulated environments where clarity, control, and long-term stability matter.
Our focus is simple: make complex operations easier to manage, more reliable to run, and strong enough to scale.