{"id":16545928,"url":"https://github.com/jowilf/sqlalchemy-file","last_synced_at":"2025-09-06T22:36:47.634Z","repository":{"id":56706825,"uuid":"523788191","full_name":"jowilf/sqlalchemy-file","owner":"jowilf","description":"SQLAlchemy-file is a SQLAlchemy extension for attaching files          to SQLAlchemy model and uploading them to various storage such as Local Storage, Amazon S3,          Rackspace CloudFiles, Google Storage and others using Apache Libcloud.","archived":false,"fork":false,"pushed_at":"2025-08-25T16:33:08.000Z","size":583,"stargazers_count":108,"open_issues_count":26,"forks_count":14,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-25T18:28:11.141Z","etag":null,"topics":["attachments","azure-storage","file-upload","libcloud","minio-storage","python3","s3-storage","sqlalchemy","sqlmodel"],"latest_commit_sha":null,"homepage":"https://jowilf.github.io/sqlalchemy-file/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jowilf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-08-11T16:09:26.000Z","updated_at":"2025-07-24T16:01:38.000Z","dependencies_parsed_at":"2023-12-25T17:48:40.976Z","dependency_job_id":"f003c27b-e87b-4257-876c-5ae5b998e7eb","html_url":"https://github.com/jowilf/sqlalchemy-file","commit_stats":{"total_commits":86,"total_committers":8,"mean_commits":10.75,"dds":"0.36046511627906974","last_synced_commit":"d8b59ad1db61b41492a65c3a1c88a1962c6f3b78"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/jowilf/sqlalchemy-file","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jowilf%2Fsqlalchemy-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jowilf%2Fsqlalchemy-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jowilf%2Fsqlalchemy-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jowilf%2Fsqlalchemy-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jowilf","download_url":"https://codeload.github.com/jowilf/sqlalchemy-file/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jowilf%2Fsqlalchemy-file/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273973960,"owners_count":25200578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attachments","azure-storage","file-upload","libcloud","minio-storage","python3","s3-storage","sqlalchemy","sqlmodel"],"created_at":"2024-10-11T19:08:11.205Z","updated_at":"2025-09-06T22:36:47.608Z","avatar_url":"https://github.com/jowilf.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sqlalchemy-file\n\n\n**SQLAlchemy-file** is a [SQLAlchemy](https://www.sqlalchemy.org/) extension for attaching files to SQLAlchemy model and\nuploading them to various storage such as Local Storage, Amazon S3, Rackspace CloudFiles, Google Storage and others\nusing [Apache Libcloud](https://github.com/apache/libcloud).\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/jowilf/sqlalchemy-file/actions\"\u003e\n    \u003cimg src=\"https://github.com/jowilf/sqlalchemy-file/actions/workflows/test.yml/badge.svg\" alt=\"Test suite\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://github.com/jowilf/sqlalchemy-file/actions\"\u003e\n    \u003cimg src=\"https://github.com/jowilf/sqlalchemy-file/actions/workflows/publish.yml/badge.svg\" alt=\"Publish\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/jowilf/sqlalchemy-file\"\u003e\n    \u003cimg src=\"https://codecov.io/gh/jowilf/sqlalchemy-file/branch/main/graph/badge.svg\" alt=\"Codecov\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://pypi.org/project/sqlalchemy-file/\"\u003e\n    \u003cimg src=\"https://badge.fury.io/py/sqlalchemy-file.svg\" alt=\"Package version\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://pypi.org/project/sqlalchemy-file/\"\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/pyversions/sqlalchemy-file?color=2334D058\" alt=\"Supported Python versions\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n\nThe key features are:\n\n* **Multiple Storage :** Use Object Storage API provided by [Apache Libcloud](https://github.com/apache/libcloud) to\n  store files. Therefore, you can store your files on Local Storage, Amazon S3, Google Cloud Storage, MinIO etc, and\n  easily switch between them. For a full list of supported providers\n  visit [supported providers page](https://libcloud.readthedocs.io/en/stable/storage/supported_providers.html) from Apache\n  Libcloud documentation.\n* **Validator :**  Provide an interface for validating each files before saving them.\n* **Size Validator :** Built-in validator for file maximum `size` validation.\n* **Content-Type Validator :** Built-in validator for file ``mimetype`` restrictions.\n* **Image Validator :** Built-in validator for image `mimetype`, `width`, `height` and `ratio` validation.\n* **Processor :** Provide an interface to easily save multiple transformation of the original files.\n* **ThumbnailGenerator :** Built-in processor to auto generate thumbnail\n* **Multiple Files :** You can attach multiple files directly to a Model.\n* **Session awareness :** Whenever an object is deleted or a rollback is performed the files uploaded during the unit of\n  work or attached to the deleted objects are automatically deleted.\n* **Meant for Evolution :** Change the storage provider anytime you want, old data will continue to work\n* **SQLModel Support:** Tested with [SQLModel](https://github.com/tiangolo/sqlmodel)\n\n---\n\n**Documentation**: [https://jowilf.github.io/sqlalchemy-file](https://jowilf.github.io/sqlalchemy-file/)\n\n**Source Code**: [https://github.com/jowilf/sqlalchemy-file](https://github.com/jowilf/sqlalchemy-file)\n\n---\n\n## Requirements\n\nA recent and currently supported version of Python (right\nnow, \u003ca href=\"https://www.python.org/downloads/\" class=\"external-link\" target=\"_blank\"\u003ePython supports versions 3.7 and\nabove\u003c/a\u003e).\n\nAs **SQLAlchemy-file** is based on **Apache Libcloud** and **SQLAlchemy**, it requires them. They will be automatically\ninstalled when you install SQLAlchemy-file.\n\n## Installation\n\n### PIP\n\n```shell\n$ pip install sqlalchemy-file\n```\n\n### Poetry\n\n```shell\n$ poetry add sqlalchemy-file\n```\n\n## Example\n\nAttaching files to models is as simple as declaring a field on the model itself\n\n```Python\nimport os\n\nfrom libcloud.storage.drivers.local import LocalStorageDriver\nfrom sqlalchemy import Column, Integer, String, create_engine\nfrom sqlalchemy.ext.declarative import declarative_base\nfrom sqlalchemy.orm import Session\nfrom sqlalchemy_file import File, FileField\nfrom sqlalchemy_file.storage import StorageManager\n\nBase = declarative_base()\n\n\n# Define your model\nclass Attachment(Base):\n    __tablename__ = \"attachment\"\n\n    id = Column(Integer, autoincrement=True, primary_key=True)\n    name = Column(String(50), unique=True)\n    content = Column(FileField)\n\n\n# Configure Storage\nos.makedirs(\"./upload_dir/attachment\", 0o777, exist_ok=True)\ncontainer = LocalStorageDriver(\"./upload_dir\").get_container(\"attachment\")\nStorageManager.add_storage(\"default\", container)\n\n# Save your model\nengine = create_engine(\n    \"sqlite:///example.db\", connect_args={\"check_same_thread\": False}\n)\nBase.metadata.create_all(engine)\n\nwith Session(engine) as session, open(\"./example.txt\", \"rb\") as local_file:\n    # from an opened local file\n    session.add(Attachment(name=\"attachment1\", content=local_file))\n\n    # from bytes\n    session.add(Attachment(name=\"attachment2\", content=b\"Hello world\"))\n\n    # from string\n    session.add(Attachment(name=\"attachment3\", content=\"Hello world\"))\n\n    # from a File object with custom filename and content_type\n    file = File(content=\"Hello World\", filename=\"hello.txt\", content_type=\"text/plain\")\n    session.add(Attachment(name=\"attachment4\", content=file))\n\n    # from a File object specifying a content path\n    session.add(Attachment(name=\"attachment5\", content=File(content_path=\"./example.txt\")))\n\n    session.commit()\n\n\n```\n\n## Related projects and inspirations\n\n* [filedepot: ](https://github.com/amol-/depot) When I was looking for a library like this, depot was the\nbest I saw. This project inspired **SQLAlchemy-file** extensively\nand some features are implemented the same.\n* [sqlalchemy-media: ](https://github.com/pylover/sqlalchemy-media) Another attachment extension for SqlAlchemy\nto manage assets which are associated with database models\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjowilf%2Fsqlalchemy-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjowilf%2Fsqlalchemy-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjowilf%2Fsqlalchemy-file/lists"}