FlaskPythonMicroservices

Minimal customer tracking for Flask microservices

Flask's philosophy is micro: do one thing well, add what you need. TinyCRM follows the same principle. Install the Python SDK, call crm.identify() in your sign-up route, and you have a complete customer database — with no new services to run and no heavy frameworks to adopt.

Installation

pip install tinycrm

Set your API key:

export TINYCRM_API_KEY=tcrm_proj_xxxxxxxxxxxx

Getting started: Flask integration

Step 1 — Basic app factory with TinyCRM

# app/__init__.py
import os
from flask import Flask
from tinycrm import TinyCRM

def create_app():
    app = Flask(__name__)

    crm = TinyCRM(api_key=os.environ["TINYCRM_API_KEY"])
    app.extensions["tinycrm"] = crm

    from .auth import auth_bp
    app.register_blueprint(auth_bp, url_prefix="/auth")

    return app

Step 2 — Identify in sign-up route

# app/auth/routes.py
from flask import request, jsonify, current_app
from . import auth_bp
from ..models import User, db

@auth_bp.post("/signup")
def signup():
    data = request.get_json()
    email = data["email"]
    name  = data.get("name", "")

    user = User(email=email, name=name)
    user.set_password(data["password"])
    db.session.add(user)
    db.session.commit()

    # Sync to TinyCRM
    crm = current_app.extensions["tinycrm"]
    crm.identify(
        email=user.email,
        name=user.name,
        status="free",
        params={"source": request.args.get("utm_source", "direct")},
    )

    return jsonify({"ok": True, "user_id": user.id})

Step 3 — Background thread for zero latency

# utils/tinycrm_helpers.py
import threading
from flask import current_app

def identify_async(email: str, name: str = "", status: str = "free", params: dict = {}):
    """Fire-and-forget identify call in a background thread."""
    crm = current_app.extensions["tinycrm"]

    def _run():
        crm.identify(email=email, name=name, status=status, params=params)

    t = threading.Thread(target=_run, daemon=True)
    t.start()

# Usage in routes:
identify_async(user.email, user.name, "free")

Step 4 — Flask-Login integration

# Using Flask-Login's user_registered signal (Flask-Security style)
# Or simply call in your registration view after login_user()

from flask_login import login_user

@auth_bp.post("/signup")
def signup():
    # ... create user ...
    login_user(user)

    crm = current_app.extensions["tinycrm"]
    crm.identify(email=user.email, name=user.name, status="free")

    return jsonify({"ok": True})

Step 5 — Celery task variant

# tasks.py
import os
from celery import shared_task
from tinycrm import TinyCRM

@shared_task
def sync_customer(email: str, name: str, status: str = "free", params: dict = {}):
    crm = TinyCRM(api_key=os.environ["TINYCRM_API_KEY"])
    crm.identify(email=email, name=name, status=status, params=params)

# Enqueue from route:
sync_customer.delay(user.email, user.name, "free")

Flask ecosystem compatibility

SQLAlchemy

Call identify() after db.session.commit().

Flask-Login

Integrate in registration routes that call login_user().

Celery + Redis

Queue as async task for high-traffic apps.

Flask Blueprints

Import shared client in any blueprint.

Flask-RESTX / API

Works in Resource.post() methods.

Gunicorn

Fully compatible with sync workers.

Flask FAQ

Where should I initialize the TinyCRM client in Flask?

Initialize once at the module level (or in your app factory) and reuse across requests. The client is stateless — it holds only the API key. You can store it on the Flask app object via app.extensions['tinycrm'] for clean access.

Can I use the SDK in a Flask Blueprint?

Yes. Import the shared TinyCRM client in any Blueprint route function. The SDK has no dependency on the Flask application context, so it works across Blueprint files without additional setup.

Does TinyCRM work with Flask async views (Python 3.8+)?

For async Flask views, use httpx with async/await instead of the default requests-based SDK. Call await async_client.identify(...) inside your async route function.

How do I avoid blocking Flask requests with the identify() call?

For synchronous Flask, run the identify() call in a background thread using Python's threading.Thread or submit it to a ThreadPoolExecutor. For Celery users, dispatch a task.

Two lines. Full customer visibility.

14-day free trial. No credit card. Works with any Python 3.8+ Flask app.

Start free trial
pip install tinycrm