random-image 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ jobs:
9
+ build-and-publish:
10
+ runs-on: ubuntu-latest
11
+ environment: release
12
+ permissions:
13
+ id-token: write
14
+
15
+ steps:
16
+ - name: Checkout code
17
+ uses: actions/checkout@v4
18
+ with:
19
+ # required for setuptools_scm to see the git tags
20
+ fetch-depth: 0
21
+
22
+ - name: Set up Python
23
+ uses: actions/setup-python@v5
24
+ with:
25
+ python-version: "3.x"
26
+
27
+ - name: Install build tools
28
+ run: python -m pip install --upgrade build
29
+
30
+ - name: Build the package
31
+ run: python -m build
32
+
33
+ - name: Publish to PyPI
34
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,224 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ *.lcov
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ # Pipfile.lock
97
+
98
+ # uv
99
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # uv.lock
103
+
104
+ # poetry
105
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
106
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
107
+ # commonly ignored for libraries.
108
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
109
+ # poetry.lock
110
+ # poetry.toml
111
+
112
+ # pdm
113
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
114
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
115
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
116
+ # pdm.lock
117
+ # pdm.toml
118
+ .pdm-python
119
+ .pdm-build/
120
+
121
+ # pixi
122
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
123
+ # pixi.lock
124
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
125
+ # in the .venv directory. It is recommended not to include this directory in version control.
126
+ .pixi/*
127
+ !.pixi/config.toml
128
+
129
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
130
+ __pypackages__/
131
+
132
+ # Celery stuff
133
+ celerybeat-schedule*
134
+ celerybeat.pid
135
+
136
+ # Redis
137
+ *.rdb
138
+ *.aof
139
+ *.pid
140
+
141
+ # RabbitMQ
142
+ mnesia/
143
+ rabbitmq/
144
+ rabbitmq-data/
145
+
146
+ # ActiveMQ
147
+ activemq-data/
148
+
149
+ # SageMath parsed files
150
+ *.sage.py
151
+
152
+ # Environments
153
+ .env
154
+ .envrc
155
+ .venv
156
+ env/
157
+ venv/
158
+ ENV/
159
+ env.bak/
160
+ venv.bak/
161
+
162
+ # Spyder project settings
163
+ .spyderproject
164
+ .spyproject
165
+
166
+ # Rope project settings
167
+ .ropeproject
168
+
169
+ # mkdocs/Zensical documentation
170
+ /site
171
+
172
+ # mypy
173
+ .mypy_cache/
174
+ .dmypy.json
175
+ dmypy.json
176
+
177
+ # Pyre type checker
178
+ .pyre/
179
+
180
+ # pytype static type analyzer
181
+ .pytype/
182
+
183
+ # Cython debug symbols
184
+ cython_debug/
185
+
186
+ # PyCharm
187
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
188
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
189
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
190
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
191
+ # .idea/
192
+
193
+ # Abstra
194
+ # Abstra is an AI-powered process automation framework.
195
+ # Ignore directories containing user credentials, local state, and settings.
196
+ # Learn more at https://abstra.io/docs
197
+ .abstra/
198
+
199
+ # Visual Studio Code
200
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
201
+ # can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
202
+ # and can be added to the global gitignore or merged into this file. However, if you prefer, you
203
+ # could uncomment the following to ignore the entire vscode folder
204
+ # .vscode/
205
+ # Temporary file for partial code execution
206
+ tempCodeRunnerFile.py
207
+
208
+ # Ruff stuff:
209
+ .ruff_cache/
210
+
211
+ # PyPI configuration file
212
+ .pypirc
213
+
214
+ # Marimo
215
+ marimo/_static/
216
+ marimo/_lsp/
217
+ __marimo__/
218
+
219
+ # Streamlit
220
+ .streamlit/secrets.toml
221
+
222
+ *.jpg
223
+
224
+ .DS_Store
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: random_image
3
+ Version: 0.0.1
4
+ Summary: Get a random image in Python.
5
+ Author-email: Taha Shieenavaz <tahashieenavaz@gmail.com>
6
+ Project-URL: Homepage, https://github.com/tahashieenavaz/random-image
7
+ Project-URL: Repository, https://github.com/tahashieenavaz/random-image
8
+ Project-URL: Documentation, https://github.com/tahashieenavaz/random-image#readme
9
+ Keywords: image,python,productivity
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: pillow
19
+ Requires-Dist: pyyaml
20
+
21
+ # random-image
22
+ Get a random image instantly.
@@ -0,0 +1,2 @@
1
+ # random-image
2
+ Get a random image instantly.
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel", "setuptools_scm"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "random_image"
7
+ dynamic = ["version"]
8
+ authors = [
9
+ { name="Taha Shieenavaz", email="tahashieenavaz@gmail.com" },
10
+ ]
11
+ description = "Get a random image in Python."
12
+ readme = "README.md"
13
+ requires-python = ">=3.9"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ "Development Status :: 4 - Beta",
19
+ "Intended Audience :: Developers",
20
+ "Topic :: Software Development :: Libraries :: Python Modules",
21
+ ]
22
+ dependencies = ["pillow", "pyyaml"]
23
+ keywords = ["image", "python", "productivity"]
24
+ license = { file = "LICENSE" }
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/tahashieenavaz/random-image"
28
+ Repository = "https://github.com/tahashieenavaz/random-image"
29
+ Documentation = "https://github.com/tahashieenavaz/random-image#readme"
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["src"]
33
+ exclude = ["tests*", "docs*", "figures*", "mermaid*", "scripts*"]
34
+
35
+ [tool.setuptools.package-data]
36
+ random_image = ["*.md", "*.txt", "*.png"]
37
+
38
+ [tool.setuptools_scm]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ from .random_image import random_image
@@ -0,0 +1,65 @@
1
+ import random
2
+ import importlib
3
+ import yaml
4
+ import requests
5
+ from typing import Optional
6
+ from functools import cache
7
+ from io import BytesIO
8
+ from PIL import Image
9
+
10
+
11
+ @cache
12
+ def repository_path(glob: Optional[str] = None):
13
+ base_path = importlib.resources.files("random_image").joinpath(f"repository")
14
+ if glob is not None:
15
+ return base_path.glob(glob)
16
+ return base_path
17
+
18
+
19
+ @cache
20
+ def list_categories():
21
+ yaml_files_generator = repository_path(glob="*.yaml")
22
+ return list(map(lambda x: x.name.replace(".yaml", ""), yaml_files_generator))
23
+
24
+
25
+ def process_category(category: Optional[str] = None):
26
+ if category is not None:
27
+ return category
28
+ return random.choice(list_categories())
29
+
30
+
31
+ @cache
32
+ def image_urls(category: str):
33
+ with (
34
+ importlib.resources.files("random_image")
35
+ .joinpath(f"repository/{category}.yaml")
36
+ .open() as stream
37
+ ):
38
+ image_urls = yaml.safe_load(stream=stream)
39
+ return image_urls
40
+
41
+
42
+ def random_image_url(category: str):
43
+ return random.choice(image_urls(category))
44
+
45
+
46
+ def random_image(
47
+ category: Optional[str] = None, as_numpy: bool = False, as_tensor: bool = False
48
+ ):
49
+ category = process_category(category)
50
+ image_url = random_image_url(category)
51
+ response = requests.get(image_url)
52
+ response.raise_for_status()
53
+ pil = Image.open(BytesIO(response.content))
54
+
55
+ if as_numpy:
56
+ import numpy
57
+
58
+ return numpy.array(pil)
59
+
60
+ if as_tensor:
61
+ import torchvision
62
+
63
+ return torchvision.io.read_image(pil)
64
+
65
+ return pil
@@ -0,0 +1,15 @@
1
+ - https://images.unsplash.com/photo-1580273916550-e323be2ae537
2
+ - https://images.unsplash.com/photo-1503376780353-7e6692767b70
3
+ - https://images.unsplash.com/photo-1765211003784-a82564cb8d3d
4
+ - https://images.unsplash.com/photo-1542362567-b07e54358753?
5
+ - https://images.unsplash.com/photo-1568605117036-5fe5e7bab0b7
6
+ - https://images.unsplash.com/photo-1492144534655-ae79c964c9d7
7
+ - https://images.unsplash.com/photo-1494976388531-d1058494cdd8
8
+ - https://images.unsplash.com/photo-1779184638442-fcbd65b0437a
9
+ - https://images.unsplash.com/photo-1567808291548-fc3ee04dbcf0
10
+ - https://images.unsplash.com/photo-1542282088-fe8426682b8f
11
+ - https://images.unsplash.com/photo-1511919884226-fd3cad34687c
12
+ - https://images.unsplash.com/photo-1533473359331-0135ef1b58bf
13
+ - https://images.unsplash.com/photo-1771962033103-da4ef275b9c0
14
+ - https://images.unsplash.com/photo-1502877338535-766e1452684a
15
+ - https://images.unsplash.com/photo-1583121274602-3e2820c69888
@@ -0,0 +1,6 @@
1
+ - https://images.unsplash.com/photo-1530281700549-e82e7bf110d6
2
+ - https://images.unsplash.com/photo-1552053831-71594a27632d
3
+ - https://images.unsplash.com/photo-1783936093098-2daf9e8ef72e
4
+ - https://images.unsplash.com/photo-1763718205007-fb085a276026
5
+ - https://images.unsplash.com/photo-1534361960057-19889db9621e
6
+ - https://images.unsplash.com/photo-1596492784531-6e6eb5ea9993
@@ -0,0 +1,15 @@
1
+ - https://images.unsplash.com/photo-1585110396000-c9ffd4e4b308
2
+ - https://images.unsplash.com/photo-1609151354448-c4a53450c6e9
3
+ - https://images.unsplash.com/photo-1777060971398-d1c72a00932a
4
+ - https://images.unsplash.com/photo-1591561582301-7ce6588cc286
5
+ - https://images.unsplash.com/photo-1782529913535-10c9427a0bb1
6
+ - https://images.unsplash.com/photo-1535241749838-299277b6305f
7
+ - https://images.unsplash.com/photo-1425082661705-1834bfd09dca
8
+ - https://images.unsplash.com/photo-1452857297128-d9c29adba80b
9
+ - https://images.unsplash.com/photo-1782419703784-d9c58fdefb0f
10
+ - https://images.unsplash.com/photo-1623686070581-5d2eb8187fc2
11
+ - https://images.unsplash.com/photo-1581872454565-822dac9367aa
12
+ - https://images.unsplash.com/photo-1481500576737-9238440343a6
13
+ - https://images.unsplash.com/photo-1779272005978-89b72b340a1d
14
+ - https://images.unsplash.com/photo-1589952283406-b53a7d1347e8
15
+ - https://images.unsplash.com/photo-1591382386627-349b692688ff
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: random_image
3
+ Version: 0.0.1
4
+ Summary: Get a random image in Python.
5
+ Author-email: Taha Shieenavaz <tahashieenavaz@gmail.com>
6
+ Project-URL: Homepage, https://github.com/tahashieenavaz/random-image
7
+ Project-URL: Repository, https://github.com/tahashieenavaz/random-image
8
+ Project-URL: Documentation, https://github.com/tahashieenavaz/random-image#readme
9
+ Keywords: image,python,productivity
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: pillow
19
+ Requires-Dist: pyyaml
20
+
21
+ # random-image
22
+ Get a random image instantly.
@@ -0,0 +1,18 @@
1
+ .gitignore
2
+ README.md
3
+ pyproject.toml
4
+ .github/workflows/publish.yaml
5
+ src/random_image/__init__.py
6
+ src/random_image/random_image.py
7
+ src/random_image.egg-info/PKG-INFO
8
+ src/random_image.egg-info/SOURCES.txt
9
+ src/random_image.egg-info/dependency_links.txt
10
+ src/random_image.egg-info/requires.txt
11
+ src/random_image.egg-info/scm_file_list.json
12
+ src/random_image.egg-info/scm_version.json
13
+ src/random_image.egg-info/top_level.txt
14
+ src/random_image/exceptions/__init__.py
15
+ src/random_image/functions/__init__.py
16
+ src/random_image/repository/car.yaml
17
+ src/random_image/repository/dog.yaml
18
+ src/random_image/repository/rabbit.yaml
@@ -0,0 +1,2 @@
1
+ pillow
2
+ pyyaml
@@ -0,0 +1,15 @@
1
+ {
2
+ "files": [
3
+ ".github/workflows/publish.yaml",
4
+ ".gitignore",
5
+ "README.md",
6
+ "pyproject.toml",
7
+ "src/random_image/__init__.py",
8
+ "src/random_image/exceptions/__init__.py",
9
+ "src/random_image/functions/__init__.py",
10
+ "src/random_image/random_image.py",
11
+ "src/random_image/repository/car.yaml",
12
+ "src/random_image/repository/dog.yaml",
13
+ "src/random_image/repository/rabbit.yaml"
14
+ ]
15
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "0.0.1",
3
+ "distance": 0,
4
+ "node": "gca79dbf54536d89535d7c45b24f2b1b2df23deab",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-11-29"
8
+ }
@@ -0,0 +1 @@
1
+ random_image