Skip to content

Commit 55ffbcf

Browse files
authored
chore: rename get url to get path (#9)
* chore: rename `get_url` to `get_path` * chore: update all references
1 parent 3d17d8d commit 55ffbcf

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ await session.commit()
5959
doc = await session.get(Document, doc.id)
6060
assert isinstance(doc.file, StorageFile)
6161

62-
url = await doc.file.get_url()
62+
url = await doc.file.get_path()
6363
await doc.file.delete()
6464
```
6565

@@ -68,7 +68,7 @@ await doc.file.delete()
6868

6969
```py
7070
doc = await session.get(Document, some_id)
71-
doc_url = await doc.file.get_url()
71+
doc_url = await doc.file.get_path()
7272
doc_size = await doc.file.get_size()
7373

7474
await doc.file.upload(another_file) # re-upload
@@ -87,7 +87,7 @@ storage = S3Storage(...)
8787
@app.post("/upload")
8888
async def upload_file(file: UploadFile):
8989
name = await storage.upload(file.file, file.filename)
90-
return {"url": await storage.get_url(name)}
90+
return {"url": await storage.get_path(name)}
9191
```
9292

9393
## License

docs/source/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ If your app runs entirely synchronously, stick with `fastapi-storages <https://g
3434
Can I extend it with other storage backends?
3535
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3636
Yes. The library’s base :class:`~async_storages.base.BaseStorage` class is extensible.
37-
You can implement new async backends (like local filesystem, Google Cloud Storage, or Azure Blob) by subclassing it and implementing the async methods ``upload``, ``get_url``, and ``delete``.
37+
You can implement new async backends (like local filesystem, Google Cloud Storage, or Azure Blob) by subclassing it and implementing the async methods ``upload``, ``get_path``, and ``delete``.
3838

3939
`fastapi-async-storages <https://github.com/stabldev/fastapi-async-storages>`_ aims to stay compatible with existing `fastapi-storages <https://github.com/aminalaee/fastapi-storages>`_ APIs, so extension patterns remain familiar.

docs/source/usage.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ Now let's see a minimal example of using :class:`~async_storages.S3Storage` in a
4242
# upload a file
4343
await storage.upload(file_obj, file_name)
4444
# get file URL
45-
url = await storage.get_url(file_name)
46-
print(url)
45+
path = await storage.get_path(file_name)
46+
print(path)
4747
# get file size
4848
size = await storage.get_size(file_name)
4949
# delete file
@@ -126,7 +126,7 @@ Let's see an example:
126126
await session.commit()
127127
128128
doc = await session.get(Document, doc.id)
129-
url = await doc.file.get_url()
129+
url = await doc.file.get_path()
130130
print(url)
131131
width, height = await doc.image.get_dimensions()
132132
print(f"Dimensions: {width}x{height}")

src/async_storages/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def get_size(self, name: str) -> int:
4040
pass
4141

4242
@abstractmethod
43-
async def get_url(self, name: str) -> str:
43+
async def get_path(self, name: str) -> str:
4444
"""
4545
Generate a URL or path to access the stored file.
4646
@@ -122,14 +122,14 @@ async def get_size(self) -> int:
122122
"""
123123
return await self._storage.get_size(self._name)
124124

125-
async def get_url(self) -> str:
125+
async def get_path(self) -> str:
126126
"""
127127
Get a URL or path to access the file.
128128
129129
:return: A URL or file path string.
130130
:rtype: str
131131
"""
132-
return await self._storage.get_url(self._name)
132+
return await self._storage.get_path(self._name)
133133

134134
async def upload(self, file: BinaryIO) -> str:
135135
"""

src/async_storages/s3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ async def get_size(self, name: str) -> int:
133133
raise
134134

135135
@override
136-
async def get_url(self, name: str) -> str:
136+
async def get_path(self, name: str) -> str:
137137
"""
138138
Generate a URL for accessing an S3 object.
139139

tests/test_integrations/test_sqlalchemy.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ async def test_sqlalchemy_with_s3(s3_test_storage: Any):
6161
assert doc.file.name == f"{file_name}"
6262

6363
# methods should work
64-
url = await doc.file.get_url()
65-
assert file_name in url
64+
path = await doc.file.get_path()
65+
assert file_name in path
6666

6767
size = await doc.file.get_size()
6868
assert size == len(file_content)
@@ -118,15 +118,15 @@ async def test_sqlalchemy_filetype_none_and_plain_string_with_s3(s3_test_storage
118118
assert doc_plain.file.name == "plain/path/file.txt"
119119

120120
# methods should work
121-
url = await doc_plain.file.get_url()
122-
assert "plain/path/file.txt" in url
121+
path = await doc_plain.file.get_path()
122+
assert "plain/path/file.txt" in path
123123

124124
# close all connections
125125
await engine.dispose()
126126

127127

128128
@pytest.mark.asyncio
129-
async def test_document_with_both_filetypes(s3_test_storage: Any):
129+
async def test_sqlalchemy_imagetype_with_s3(s3_test_storage: Any):
130130
storage = s3_test_storage
131131
# assign s3_storage to file column
132132
Document.__table__.columns.image.type.storage = storage

tests/test_s3_storage.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ async def test_s3_storage_methods(s3_test_env: Any):
2525
assert returned_name == storage.get_name(file_name)
2626

2727
# get url test without custom domain or querystring_auth
28-
url = await storage.get_url(file_name)
29-
assert file_name in url
28+
path = await storage.get_path(file_name)
29+
assert file_name in path
3030

3131
# get size test
3232
size = await storage.get_size(file_name)
@@ -54,11 +54,11 @@ async def test_s3_storage_querystring_auth(s3_test_env: Any):
5454
)
5555

5656
name = "test/file.txt"
57-
url = await storage.get_url(name)
57+
path = await storage.get_path(name)
5858

59-
assert url.count("AWSAccessKeyId=") == 1
60-
assert url.count("Signature=") == 1
61-
assert url.count("Expires=") == 1
59+
assert path.count("AWSAccessKeyId=") == 1
60+
assert path.count("Signature=") == 1
61+
assert path.count("Expires=") == 1
6262

6363

6464
@pytest.mark.asyncio
@@ -75,10 +75,10 @@ async def test_s3_storage_custom_domain(s3_test_env: Any):
7575
)
7676

7777
name = "test/file.txt"
78-
url = await storage.get_url(name)
78+
path = await storage.get_path(name)
7979

80-
assert url.startswith("http://cdn.example.com/")
81-
assert name in await storage.get_url(name)
80+
assert path.startswith("http://cdn.example.com/")
81+
assert name in await storage.get_path(name)
8282

8383

8484
@pytest.mark.asyncio

0 commit comments

Comments
 (0)