Skip to main content

A python library to integrate python APIs in Mycelium API Gateway

Project description

Mycelium HTTP Tools

A python library to integrate python APIs in Mycelium API Gateway.

Installation

Basic Installation

Install the core library without optional dependencies:

pip install mycelium-http-tools

With FastAPI Support

To use the FastAPI middleware for profile extraction, install with the FastAPI extra:

pip install mycelium-http-tools[fastapi]

This will install the additional dependencies:

  • fastapi>=0.104.0,<1.0.0

Development Installation

For development with all dependencies:

pip install mycelium-http-tools[dev,fastapi]

Usage

Basic Usage

from myc_http_tools.models.profile import Profile
from myc_http_tools.models.owner import Owner

# Create and use Profile objects
profile = Profile(
    acc_id="123e4567-e89b-12d3-a456-426614174000",
    is_subscription=True,
    is_staff=True,
    is_manager=False,
    owner_is_active=True,
    account_is_active=True,
    account_was_approved=True,
    account_was_archived=False,
    account_was_deleted=False,
    owners=[Owner(...)]
)

FastAPI Integration

If you installed with FastAPI support, you can use the middleware:

from fastapi import FastAPI
from fastapi.middleware.base import BaseHTTPMiddleware
from myc_http_tools.fastapi import profile_middleware

app = FastAPI()
app.add_middleware(BaseHTTPMiddleware, dispatch=profile_middleware)

@app.get("/")
async def my_route(request: Request):
    profile = request.state.profile  # Profile extracted from x-mycelium-profile header
    # ... use the profile

Or use the utility function directly:

from fastapi import FastAPI, Depends
from myc_http_tools.fastapi import get_profile_from_request

app = FastAPI()

@app.get("/")
async def my_route(request: Request):
    profile = get_profile_from_request(request)
    # ... use the profile

Features

  • Profile Management: Core Profile model with filtering and permission management
  • FastAPI Middleware (optional): Extract profiles from HTTP headers
  • Flexible Installation: Install only what you need

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mycelium_http_tools-0.1.0a3-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file mycelium_http_tools-0.1.0a3-py3-none-any.whl.

File metadata

File hashes

Hashes for mycelium_http_tools-0.1.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 91d6e1d4e199ea0ae1a841125617c10b988a80509ed821b2203aa01ebf23c2d8
MD5 f5ab11c4a5055d64e4bf5b1c6478613b
BLAKE2b-256 d7edf53b9a6fb14ab38e39a51b5b7a400e773fea1be9920b8bedd9370c86d143

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page