Skip to main content

FStorage

Fstorage, Secure file storage, SYNC/ASYNC clients, easy to learn, fast to code.

Package version Supported Python versions Total downloads


Source Code: https://github.com/ispaneli/fstorage


FStorage is a simple asynchronous secure file storage for microservices.

It is implemented on the FastAPI web framework.

To run the file storage, you need:

WARNING: With the usual installation of pip install fstorage, the requirements are not installed (for more info, see How to install)!


How to install with requirements

To deploy the FStorage on the server:

pip install 'fstorage[server]'

To use synchronous client:

pip install 'fstorage[sync_client]'

To use asynchronous client:

pip install 'fstorage[async_client]'

How to deploy storage

Configure virtual environment variables in terminal:

export POSTGRESQL_URL="postgresql+asyncpg://<db_username>:<db_password>@<db_host>:<db_port>/<db_name>"
export STORAGE_PATH="/Users/<local_username>/.fstorage/storage"

Configure logging.ini:

[loggers]
keys=root

[handlers]
keys=logfile, logconsole

[formatters]
keys=logformatter

[logger_root]
level=INFO
handlers=logfile, logconsole

[formatter_logformatter]
format=[%(asctime)s.%(msecs)03d] %(levelname)s [%(thread)d] - %(message)s

[handler_logfile]
class=handlers.RotatingFileHandler
level=INFO
args=('/Users/<local_username>/.fstorage/logfile.log', 'a')
formatter=logformatter

[handler_logconsole]
class=handlers.logging.StreamHandler
level=INFO
args=()
formatter=logformatter

Run this code:

import os

from fstorage.server import storage_run


if __name__ == '__main__':
    storage_run(
        storage_path=os.getenv('STORAGE_PATH'),
        log_config_path="logging.ini",
        
        db_async_url=os.getenv('POSTGRESQL_URL'),
        db_echo=True,
        db_future=True,
        db_drop_all=False,

        host='127.0.0.1',
        port=8_000,
        reload=False,
        workers_num=1
    )

How to use synchronous client

from fstorage.client.synch.client import SyncClient


if __name__ == '__main__':
    client = SyncClient("http://127.0.0.1:8000")

    upload_response: dict = client.upload(open("example.file", 'rb'))
    print(upload_response)
    # {'id': "<file_id>"}

    get_response: dict = client.get(upload_response['id'])
    print(get_response)
    # {'filename': "example.file", 'bytes': '<data_as_bytes>'}

    client.delete(upload_response['id'])

    try:
        client.get(upload_response['id'])
    except FileExistsError as error:
        print(error)
        # "The file with this ID doesn't exist."

    try:
        client.delete(upload_response['id'])
    except FileExistsError as error:
        print(error)
        # "The file with this ID doesn't exist."

How to use asynchronous client

import asyncio

from fstorage.client.asynch.client import AsyncClient


async def example():
    client = AsyncClient("http://127.0.0.1:8000")

    upload_response: dict = await client.upload(open("example.file", 'rb'))
    print(upload_response)
    # {'id': "<file_id>"}

    get_response: dict = await client.get(upload_response['id'])
    print(get_response)
    # {'filename': "example.file", 'bytes': '<data_as_bytes>'}

    await client.delete(upload_response['id'])

    try:
        await client.get(upload_response['id'])
    except FileExistsError as error:
        print(error)
        # "The file with this ID doesn't exist."

    try:
        await client.delete(upload_response['id'])
    except FileExistsError as error:
        print(error)
        # "The file with this ID doesn't exist."


if __name__ == '__main__':
    asyncio.run(example())

License

This project is licensed under the terms of the MIT license.

Release files for fstorage 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fstorage 0.0.3
File Size Uploaded Provenance Actions
fstorage-0.0.3.tar.gz 11.0 kB Without provenance Details for fstorage-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fstorage 0.0.3
File Interpreter ABI Platform Actions
fstorage-0.0.3-py3-none-any.whl Python 3 none any Details for fstorage-0.0.3-py3-none-any.whl

Total release size: 22.9 kB

Release files / fstorage-0.0.3.tar.gz

Download URL fstorage-0.0.3.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8c6618e22709ea7b48157fc42daae171e82cbbbd9a8239ea137918cad0b7c70d
BLAKE2b-256 checksum
How to use checksums
6c50308b4b476438b878d44769143e76ee391d02a5f6fc388efbd1b4a28ce7a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / fstorage-0.0.3-py3-none-any.whl

Download URL fstorage-0.0.3-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1b8dc9411f2deb94871ac7f8e861637085614a37bdc1dbc8f3ad2be7cd6d99d
BLAKE2b-256 checksum
How to use checksums
f8d51b6073d4b3bb2fd8739e2badb66e4f5897d82a5ffc866499c5a81105b13a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Security for fstorage 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page