├── .gitignore ├── LICENSE ├── README.md ├── documentation.md ├── imgbbpy ├── __init__.py ├── aio.py ├── imgbb.py ├── imgerrors.py └── imggallery.py ├── requirements.txt └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | 4 | # Distribution / packaging 5 | .Python 6 | build/ 7 | develop-eggs/ 8 | dist/ 9 | downloads/ 10 | eggs/ 11 | .eggs/ 12 | lib/ 13 | lib64/ 14 | parts/ 15 | sdist/ 16 | var/ 17 | wheels/ 18 | pip-wheel-metadata/ 19 | share/python-wheels/ 20 | *.egg-info/ 21 | .installed.cfg 22 | *.egg 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021-2022 scrazzz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a 6 | copy of this software and associated documentation files (the "Software"), 7 | to deal in the Software without restriction, including without limitation 8 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | and/or sell copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # imgbbpy 2 | An Asynchronous and Synchronous API Wrapper for the Imgbb API. 3 | 4 | ## Installation 5 | Install imgbbpy via `pip`. 6 | 7 | ```sh 8 | pip install imgbbpy 9 | ``` 10 | imgbbpy requires Python 3.7+ 11 | 12 | ## Quickstart 13 | Asynchronous usage: 14 | ```py 15 | import asyncio 16 | from imgbbpy.aio import Client 17 | 18 | async def main(): 19 | client = Client('API KEY') 20 | image = await client.upload(file='path/to/image.jpeg') 21 | print(image.url) 22 | 23 | await client.close() 24 | 25 | asyncio.get_event_loop().run_until_complete(main()) 26 | ``` 27 | 28 | Synchronous usage: 29 | ```py 30 | from imgbbpy import Client 31 | 32 | client = Client('API KEY') 33 | image = client.upload(file='path/to/image.png') 34 | print(image.url) 35 | ``` 36 | 37 | You can get an API Key from https://api.imgbb.com. 38 | 39 | ## Documentation 40 | Documentation can be found in the `documentation.md` file. 41 | 42 | ## License 43 | MIT, see LICENSE for more details. 44 | -------------------------------------------------------------------------------- /documentation.md: -------------------------------------------------------------------------------- 1 | # imgbbpy 2 | An Asynchronous and Synchronous API Wrapper for the Imgbb API. 3 | 4 | # Table of Contents 5 | - API Reference 6 | 7 | - [Client](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#client) 8 | - [Async Client](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#async-client) 9 | - [Sync Client](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#sync-client) 10 | 11 | - [Models](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#models) 12 | - [Image](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#image) 13 | 14 | - [Exceptions](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#exceptions) 15 | - [ImgbbError](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#imgbbimgbberrors-imgbberror) 16 | - [MinExpirationLimit](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#imgbbimgbberrors-minexpirationlimit) 17 | - [MaxExpirationLimit](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#imgbbimgbberrors-maxexpirationlimit) 18 | 19 | ## API Reference 20 | 21 | ### Client 22 | #### Async Client 23 | *`class imgbbpy.aio.Client(key)`* 24 | Represents an asynchronous client connection that connects to the Imgbb API for uploading. 25 | 26 | Parameters: 27 | * __key__ (str) - The API Key required to make a connection with the API. 28 | 29 | ` ` `await upload(*, url, file, name, expiration)` 30 | Parameters: 31 | * __url__ (Optional[str]) - The URL of the image to upload. The image to upload should not be more than 32 MB. 32 | * __file__ (Optional[str]) - The path of the image to upload. The image to upload should not be more than 32 MB. 33 | * __name__ (Optional[str]) - The name of the image to set when uploading. 34 | * __expiration__ (Optional[int]) - The expiration to set when you want the image to be auto deleted after certain time (in seconds 60 - 15552000). The uploaded image gets deleted automatically after 2592000 seconds (30 days) by default. 35 | 36 | __Note__: 37 | * Both `url` and `file` are optional, but either `url` or `file` is needed to upload the image. 38 | 39 | Returns: 40 | * [__Image__](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#image) - The uploaded image. 41 | 42 | Raises: 43 | * __TypeError__ - Raised when `expiration` is not of type int. 44 | * [__ImgbbError__](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#imgbbimgbberrors-imgbberror) - Raised when: 45 | Both `url` and `file` is given. 46 | Either `url` or `file` is not given. 47 | An uncaught error occurs. 48 | * [__MinExpirationLimit__](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#imgbbimgbberrors-minexpirationlimit) - Raised when given `expiration` is lower than 60 seconds. 49 | * [__MaxExpirationLimit__](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#imgbbimgbberrors-maxexpirationlimit) - Raised when given `expiration` is more than 15552000 seconds. 50 | 51 | #### Sync Client 52 | *`class imgbbpy.imgbb.Client(key)`* 53 | Represents a synchronous client connection that connects to the Imgbb API for uploading. 54 | Parameters: 55 | * __key__ (str) - The API Key required to make a connection with the API. 56 | 57 | ` ` `upload(*, url, file, name, expiration)` 58 | Parameters: 59 | * __url__ (Optional[str]) - The URL of the image to upload. The image to upload should not be more than 32 MB. 60 | * __file__ (Optional[str]) - The path of the image to upload. The image to upload should not be more than 32 MB. 61 | * __name__ (Optional[str]) - The name of the image to set when uploading. 62 | * __expiration__ (Optional[int]) - The expiration to set when you want the image to be auto deleted after certain time (in seconds 60 - 15552000). The uploaded image gets deleted automatically after 2592000 seconds (30 days) by default. 63 | 64 | __Note__: 65 | * Both `url` and `file` are optional, but either `url` or `file` is needed to upload the image. 66 | 67 | Returns: 68 | * [__Image__](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#image) - The uploaded image. 69 | 70 | Raises: 71 | * __TypeError__ - Raised when `expiration` is not of type int. 72 | * [__ImgbbError__](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#imgbbimgbberrors-imgbberror) - Raised when: 73 | Both `url` and `file` is given. 74 | Either `url` or `file` is not given. 75 | An uncaught error occurs. 76 | * [__MinExpirationLimit__](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#imgbbimgbberrors-minexpirationlimit) - Raised when given `expiration` is lower than 60 seconds. 77 | * [__MaxExpirationLimit__](https://github.com/scrazzz/imgbbpy/blob/master/documentation.md#imgbbimgbberrors-maxexpirationlimit) - Raised when given `expiration` is more than 15552000 seconds. 78 | 79 | ### Models 80 | #### Image 81 | *`class imgbbpy.imgbbgallery.Image`* 82 | Represents the uploaded image. 83 | This is returned from `Client.upload`. 84 | 85 | * __id__ (str) - The ID of the image. 86 | * __filename__ - (str) - The filename of the image. 87 | * __url__ (str) - The URL of the image. 88 | * __size__ (int) - The size of the image in bytes. 89 | * __expiration__ (int) - The time left (in seconds) for the image to expire. 90 | * __mime__ (str) - The mime type of the image. 91 | * __extension__ (str) - The extension of the image. 92 | * __delete_url__ (str) - The delete URL to delete the image. 93 | 94 | ### Exceptions 95 | 96 | #### *`class imgbb.imgbberrors.ImgbbError`* 97 | 98 | Base class for all Imgbb exceptions. 99 | 100 | #### *`class imgbb.imgbberrors.MinExpirationLimit`* 101 | 102 | Exeption raised when the expiration given is less than 60 seconds. 103 | 104 | #### *`class imgbb.imgbberrors.MaxExpirationLimit`* 105 | 106 | Exeption raised when the expiration given is more than 15552000 seconds. 107 | -------------------------------------------------------------------------------- /imgbbpy/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2021-2022 scrazzz 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | """ 24 | 25 | __title__ = 'imgbbpy' 26 | __author__ = 'scrazzz' 27 | __license__ = 'MIT' 28 | __copyright__ = 'Copyright 2021-2022 scrazzz' 29 | __version__ = '0.1.4' 30 | 31 | from .imgbb import Client 32 | from .imgerrors import * 33 | from .imggallery import * 34 | -------------------------------------------------------------------------------- /imgbbpy/aio.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2021-2022 scrazzz 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | """ 24 | 25 | from typing import Any, ClassVar 26 | 27 | import aiohttp 28 | from yarl import URL 29 | 30 | from .imgerrors import * 31 | from .imggallery import * 32 | 33 | class Client: 34 | """Represents an asynchronous client connection that connects to the Imgbb API for uploading. 35 | 36 | Parameters 37 | ---------- 38 | key: str 39 | The API Key required to make a connection with the API. 40 | 41 | Methods 42 | ------- 43 | await upload(*, url=None, file=None, name="", expiration=None) 44 | Uploads the image. 45 | 46 | await close() 47 | Closes the Client Session. 48 | """ 49 | 50 | API_URL: ClassVar = 'https://api.imgbb.com/1/upload' 51 | 52 | def __init__(self, key: str) -> None: 53 | self.key: str = key 54 | self._session: aiohttp.ClientSession = aiohttp.ClientSession() 55 | 56 | async def upload( 57 | self, 58 | *, 59 | url: str = None, 60 | file: str = None, 61 | name: str = "image", 62 | expiration: int = None 63 | ) -> Image: 64 | """Uploads the image. 65 | 66 | Note 67 | ----- 68 | * Both `url` and `file` are optional, but either `url` or `file` is required for uploading the image. 69 | * The image to upload should not be more than 32 MB. 70 | * Image gets deleted automatically after 2592000 seconds (30 days) by default. 71 | 72 | Parameters 73 | ---------- 74 | url: str, optional 75 | The URL of the image to upload. 76 | file: str, optional 77 | The path of the image to upload. 78 | name: str, optional 79 | The name of the file to set when uploading. 80 | expiration: int, optional 81 | The expiration to set when you want the uploaded image to be auto deleted after certain time (in seconds 60-15552000). 82 | 83 | Raises 84 | ------ 85 | TypeError 86 | Raised when `expiration` is not of type int. 87 | 88 | ImgbbError 89 | Raised when both `url` and `file` is given. 90 | Raised when either `url` or `file` is not given. 91 | Raised when an uncaught error occurs. 92 | 93 | MinExpirationLimit 94 | Raised when given `expiration` is lower than 60 seconds. 95 | 96 | MaxExpirationLimit 97 | Raised when given `expiration` is more than 15552000 seconds. 98 | 99 | Returns 100 | ------- 101 | Image: class 102 | The uploaded image. 103 | """ 104 | 105 | if file and url: 106 | raise ImgbbError('Cannot upload both URL and file.') 107 | if not file and not url: 108 | raise ImgbbError('Needs either URL or file to upload.') 109 | if url is not None: 110 | yarl_url: URL = URL(url) 111 | if not (yarl_url.scheme or yarl_url.host): 112 | raise TypeError('url paramter did not get a valid URL') 113 | 114 | # checking for expiration type. 115 | # if expiration is None, pass 116 | # else, check for max and min expiration limits. 117 | if expiration is None: 118 | pass 119 | elif not isinstance(expiration, int): 120 | raise TypeError('expiration should be an int.') 121 | 122 | if expiration is not None: 123 | if expiration < 60: 124 | raise MinExpirationLimit('Minimum expiration limit is 60 seconds.') 125 | if expiration > 15552000: 126 | raise MaxExpirationLimit('Maximum expiration limit is 15552000 seconds.') 127 | 128 | data = {} 129 | params = { 130 | 'key': self.key, 131 | 'name': name 132 | } 133 | 134 | try: 135 | data['image'] = open(file, 'rb') if file else url # type: ignore 136 | except OSError: 137 | raise TypeError('Invalid argument for parameter file. Did you meant to use url parameter?') 138 | 139 | if expiration: 140 | params['expiration'] = str(expiration) 141 | 142 | async with self._session.post(self.API_URL, params=params, data=data) as post: 143 | js: Any = await post.json() 144 | 145 | if post.status == 200: 146 | data = js['data'] 147 | return Image( 148 | id = data['id'], 149 | filename = data['image']['filename'], 150 | url = data['url'], 151 | size = data['size'], 152 | expiration = data['expiration'], 153 | mime = data['image']['mime'], 154 | extension = data['image']['extension'], 155 | delete_url = data['delete_url'] 156 | ) 157 | else: 158 | raise ImgbbError(f"Error {js['status_code']}: {js['error']['message']}") 159 | 160 | async def close(self): 161 | """Closes the Client Session.""" 162 | await self._session.close() 163 | -------------------------------------------------------------------------------- /imgbbpy/imgbb.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2021-2022 scrazzz 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | """ 24 | 25 | from base64 import b64encode 26 | from typing import Any, ClassVar 27 | 28 | import requests 29 | from yarl import URL 30 | 31 | from .imgerrors import * 32 | from .imggallery import * 33 | 34 | class Client: 35 | """Represents a synchronous client connection that connects to the Imgbb API for uploading. 36 | 37 | Parameters 38 | ---------- 39 | key: str 40 | The API Key required to make a connection with the API. 41 | 42 | Methods 43 | ------- 44 | upload(*, url=None, file=None, name="", expiration=None) 45 | Uploads the image. 46 | """ 47 | 48 | API_URL: ClassVar = 'https://api.imgbb.com/1/upload' 49 | 50 | def __init__(self, key) -> None: 51 | self.key: str = key 52 | self._session: requests.Session = requests.Session() 53 | 54 | def upload( 55 | self, 56 | *, 57 | file: str = None, 58 | url: str = None, 59 | name: str = "image", 60 | expiration: int = None 61 | ) -> Image: 62 | """Uploads the image. 63 | 64 | Note 65 | ----- 66 | * Both `url` and `file` are optional, but either `url` or `file` is required for uploading the image. 67 | * The image to upload should not be more than 32 MB. 68 | * Image gets deleted automatically after 2592000 seconds (30 days) by default. 69 | 70 | Parameters 71 | ---------- 72 | url: str, optional 73 | The URL of the image to upload. 74 | file: str, optional 75 | The path of the image to upload. 76 | name: str, optional 77 | The name of the file. This is automatically set if not given. 78 | expiration: int, optional 79 | Use this if you want the uploaded image to be auto deleted after certain time (in seconds 60-15552000). 80 | 81 | Raises 82 | ------ 83 | TypeError 84 | Raised when `expiration` is not of type int. 85 | 86 | ImgbbError 87 | Raised when both `url` and `file` is given. 88 | Raised when either `url` or `file` is not given. 89 | Raised when an uncaught error occurs. 90 | 91 | MinExpirationLimit 92 | Raised when given `expiration` is lower than 60 seconds. 93 | 94 | MaxExpirationLimit 95 | Raised when given `expiration` is more than 15552000 seconds. 96 | 97 | Returns 98 | ------- 99 | Image: class 100 | The uploaded image. 101 | """ 102 | 103 | if file and url: 104 | raise ImgbbError('Cannot upload both URL and file.') 105 | if not file and not url: 106 | raise ImgbbError('Needs either URL or file to upload.') 107 | if url is not None: 108 | yarl_url: URL = URL(url) 109 | if not (yarl_url.scheme or yarl_url.host): 110 | raise TypeError('url paramter did not get a valid URL') 111 | 112 | if expiration is None: 113 | pass 114 | elif not isinstance(expiration, int): 115 | raise TypeError('expiration should be an int.') 116 | 117 | if expiration is not None: 118 | if expiration < 60: 119 | raise MinExpirationLimit('Minimum expiration limit is 60 seconds.') 120 | if expiration > 15552000: 121 | raise MaxExpirationLimit('Maximum expiration limit is 15552000 seconds.') 122 | 123 | params = { 124 | 'key': self.key, 125 | 'name': name, 126 | 'image': b64encode(open(file, 'rb').read()) if file else url 127 | } 128 | 129 | if expiration: 130 | params['expiration'] = str(expiration) 131 | 132 | r: requests.Response = self._session.post(self.API_URL, params) 133 | js: Any = r.json() 134 | 135 | if r.status_code == 200: 136 | data = js['data'] 137 | return Image( 138 | id = data['id'], 139 | filename = data['image']['filename'], 140 | url = data['url'], 141 | size = data['size'], 142 | expiration = data['expiration'], 143 | mime = data['image']['mime'], 144 | extension = data['image']['extension'], 145 | delete_url = data['delete_url'] 146 | ) 147 | else: 148 | raise ImgbbError(f"Error {js['status_code']}: {js['error']['message']}") 149 | -------------------------------------------------------------------------------- /imgbbpy/imgerrors.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2021-2022 scrazzz 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | """ 24 | 25 | class ImgbbError(Exception): 26 | """Base exception for all imgbbpy errors.""" 27 | pass 28 | 29 | class MaxExpirationLimit(ImgbbError): 30 | """Exception for maximum expiration limit.""" 31 | pass 32 | 33 | class MinExpirationLimit(ImgbbError): 34 | """Exception for minimum expiration limit.""" 35 | pass 36 | -------------------------------------------------------------------------------- /imgbbpy/imggallery.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2021-2022 scrazzz 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | """ 24 | 25 | import dataclasses 26 | 27 | @dataclasses.dataclass 28 | class Image: 29 | """Represents an Image. 30 | 31 | This is returned from `Client.upload`. 32 | 33 | Attributes 34 | ---------- 35 | id: str 36 | The ID of the image. 37 | filename: str 38 | The filename of the image. 39 | url: str 40 | The URL of the image. 41 | size: int 42 | The size of the image in bytes. 43 | expiration: int 44 | The time left (in seconds) for the image to expire. 45 | mime: str 46 | The mime type of the image. 47 | extension: str 48 | The extension of the image. 49 | delete_url: str 50 | The delete URL to delete the image. 51 | """ 52 | 53 | id: str 54 | filename: str 55 | url: str 56 | size: int 57 | expiration: int 58 | mime: str 59 | extension: str 60 | delete_url: str 61 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | aiohttp 2 | requests -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import re 2 | import setuptools 3 | 4 | with open('requirements.txt') as f: 5 | requirements = f.read().splitlines() 6 | 7 | with open('imgbbpy/__init__.py') as f: 8 | version = re.search(r"__version__ = '([\d\.]+)'", f.read(), re.MULTILINE)[1] # type: ignore 9 | 10 | with open('README.md') as f: 11 | readme = f.read() 12 | 13 | setuptools.setup( 14 | name='imgbbpy', 15 | author='scrazzz', 16 | url='https://github.com/scrazzz/imgbbpy/', 17 | project_urls={ 18 | 'Documentation': 'https://github.com/scrazzz/imgbbpy/blob/main/documentation.md', 19 | 'Issue tracker': 'https://github.com/scrazzz/imgbbpy/issues' 20 | }, 21 | version=version, 22 | packages=['imgbbpy'], 23 | license='MIT', 24 | description='An Asynchronous and Synchronous API Wrapper for the Imgbb API.', 25 | long_description=readme, 26 | long_description_content_type='text/markdown', 27 | include_package_data=True, 28 | install_requires=requirements, 29 | python_requires='>=3.7.0' 30 | ) 31 | --------------------------------------------------------------------------------