Look up information about photos and collections of photos from Flickr
Project description
flickr-photos-api
This is a library for getting information about photos from the Flickr API.
It's not a general-purpose Flickr API library. It's designed for use at the Flickr Foundation, and provides a subset of Flickr API methods with the following goals:
-
Abstract away some of the details of the Flickr API -- for example, licenses are returned as complete dictionaries, rather than as the numeric license IDs returned by Flickr API methods.
-
Apply types to all results, so the Flickr API can be used safely in a typed context.
Design
This library tries to balance efficiency and reusability.
-
We don't want to have to write a new Flickr API library for every project -- we want to be able to reuse as much code as possible.
-
The Flickr API can return a lot of fields, which is controlled by the
extras
query parameter.For example, when you look up a collection of photos, you could add
extras=license
to include information about the license of each photo; or you could addextras=title,description
to include information about the title and license.We don't want to fetch more fields than are necessary -- that's a lot of extra data!
We try to provide a set of methods that reuse the most code, but allow the flexibility for callers to decide which extras
they want.
Examples
>>> from flickr_photos_api import FlickrPhotosApi
>>> api = FlickrPhotosApi(api_key="…", user_agent="…")
>>> photo = api.get_single_photo(photo_id="14898030836")
>>> photo
{'id': '14898030836', 'title': 'NASA Scientists Says', …}
>>> photo["license"]
{'id': 'cc-by-2.0', 'label': 'CC BY 2.0', 'url': 'https://creativecommons.org/licenses/by/2.0/'}
>>> photo["url"]
'https://www.flickr.com/photos/lassennps/14898030836/'
Usage
-
Install flickr-photos-api from PyPI:
$ pip install flickr-photos-api
-
Construct an instance of
FlickrPhotosApi
. You need to pass a user-agent that identifies you, and a Flickr API key.from flickr_photos_api import FlickrPhotosApi api = FlickrPhotosApi(api_key="…", user_agent="…")
-
Call methods on FlickrPhotosApi. The methods meant for public use are:
def get_single_photo(photo_id: str) -> SinglePhoto: ... def get_photos_in_album(user_url: str, album_id: str) -> PhotosInAlbum: ... def get_photos_in_gallery(gallery_id: str) -> PhotosInGallery: ... def get_public_photos_by_user(user_url: str) -> CollectionOfPhotos: ... def get_photos_in_group_pool(group_url: str) -> PhotosInGroup: ... def get_photos_with_tag(tag: str) -> CollectionOfPhotos: ...
Methods that return collections of photos also support
page
andper_page
parameters to control pagination.
Development
If you want to make changes to the library, there are instructions in CONTRIBUTING.md.
License
This project is dual-licensed as Apache-2.0 and MIT.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flickr_photos_api-1.14.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a072b2c0a7229ed7031681ebe90abc791e5d2a521d990099db4dfcfc6e4b1782 |
|
MD5 | c318091db9837d794bf7f9bc43ce48ff |
|
BLAKE2b-256 | 82651dca05b3ad76690711d4e94303f347692edf97e457aed2869fd899193cfa |