Fstorage, Secure file storage, SYNC/ASYNC clients, easy to learn, fast to code.
Project description
Fstorage, Secure file storage, SYNC/ASYNC clients, easy to learn, fast to code.
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:
How to install
To deploy the FStorage on the server:
pip install fstorage[server]
To use a synchronous client:
pip install fstorage[sync_client]
To use a asynchronous client:
pip install fstorage[async_client]
How to use
1. Server example
Configure virtual environment variables in terminal:
export POSTGRESQL_URL="postgres://<username>:<password>@<ip_address>:<port>/<database_name>"
export STORAGE_PATH="/Users/<local_user>/.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_user>/.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
)
2. Sync client example
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."
3. Async client example
import asyncio
from src.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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fstorage-0.0.1.tar.gz
(10.6 kB
view hashes)
Built Distribution
Close
Hashes for fstorage-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e84e8340d71fdee69d1b586d63a7ae6ba63dab60a06f66d956e40a621bf0555e |
|
MD5 | d03ad132fee7f1951f12dc1c5310d48d |
|
BLAKE2b-256 | d13e7e0cddc9250ac96a71d7d455eccd6d0c5800a73b79fc04ee2a5413dfbdbd |