https://github.com/ispaneli/fstorage
Fstorage, Secure file storage, SYNC/ASYNC clients, easy to learn, fast to code.
https://github.com/ispaneli/fstorage
aiohttp-client api-client asgi async asyncio client-server cryptography fastapi file-manager filesystem python python-types python3 requests security storage-api storage-engine swagger swagger-ui uvicorn
Last synced: 9 days ago
JSON representation
Fstorage, Secure file storage, SYNC/ASYNC clients, easy to learn, fast to code.
- Host: GitHub
- URL: https://github.com/ispaneli/fstorage
- Owner: ispaneli
- License: mit
- Created: 2023-01-23T15:06:12.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-03-22T18:04:20.000Z (about 2 years ago)
- Last Synced: 2025-03-27T19:22:49.480Z (27 days ago)
- Topics: aiohttp-client, api-client, asgi, async, asyncio, client-server, cryptography, fastapi, file-manager, filesystem, python, python-types, python3, requests, security, storage-api, storage-engine, swagger, swagger-ui, uvicorn
- Language: Python
- Homepage: https://pypi.org/project/fstorage
- Size: 157 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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:
* **PostgreSQL****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))!
---
## How to install with requirements
To deploy the FStorage on the **server**:
```bash
pip install 'fstorage[server]'
```To use **synchronous client**:
```bash
pip install 'fstorage[sync_client]'
```To use **asynchronous client**:
```bash
pip install 'fstorage[async_client]'
```---
## How to deploy storage
Configure virtual environment variables in terminal:
```bash
export POSTGRESQL_URL="postgresql+asyncpg://:@:/"
export STORAGE_PATH="/Users//.fstorage/storage"
```Configure **logging.ini**:
```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//.fstorage/logfile.log', 'a')
formatter=logformatter[handler_logconsole]
class=handlers.logging.StreamHandler
level=INFO
args=()
formatter=logformatter
```Run this code:
```python
import osfrom 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
```python
from fstorage.client.synch.client import SyncClientif __name__ == '__main__':
client = SyncClient("http://127.0.0.1:8000")upload_response: dict = client.upload(open("example.file", 'rb'))
print(upload_response)
# {'id': ""}get_response: dict = client.get(upload_response['id'])
print(get_response)
# {'filename': "example.file", '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
```python
import asynciofrom 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': ""}get_response: dict = await client.get(upload_response['id'])
print(get_response)
# {'filename': "example.file", '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](https://github.com/ispaneli/fstorage/blob/master/LICENSE).