Skip to main content

HTTP range implementation based on Fastapi

Project description

Fastapi Range Response

Description

  • HTTP range response for Fastapi
  • Part of the code is based on changes to BáiZé FileResponse
  • 实现了HTTP Range的响应类, 继承自starlette.response.Response, 可使用本机文件或sftp协议进行读取文件

Install

pip install fastapi_range_response

QuickStart

A short example for fastapi application

import asyncio
import asyncssh
from fastapi import FastAPI
from fastapi import Query
from fastapi_range_response import FileRangeResponse, AsyncsshRangeResponse

app = FastAPI()


@app.get('/local_file')
async def download_local_file(full_path: str = Query()):
    return FileRangeResponse(full_path, media_type='application/octet-stream')


@app.get('/download_sftp_file')
async def download_sftp_file(full_path: str = Query()):
    ssh_client = await asyncio.wait_for(
        asyncssh.connect(host='xxx', port=22, username='xxx', password='xxxx', known_hosts=None),
        timeout=10
    )
    return AsyncsshRangeResponse(full_path, ssh_client, done_close=True)


if __name__ == '__main__':
    import uvicorn

    uvicorn.run(app)

Project details


Download files

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

Source Distribution

fastapi_range_response-0.1.tar.gz (6.9 kB view details)

Uploaded Source

File details

Details for the file fastapi_range_response-0.1.tar.gz.

File metadata

  • Download URL: fastapi_range_response-0.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for fastapi_range_response-0.1.tar.gz
Algorithm Hash digest
SHA256 528694bbb73bb7027e43ad6ee9218a23b9a2553b59d478e40d27700b4b4f7a12
MD5 a4f7d5860c25cc6150d9700b504e1f1a
BLAKE2b-256 674f9be5ebdc724a564a52945a05349c761397c2b079432cc65c4593cbdcd3cc

See more details on using hashes here.

Supported by

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