flickr-photos-api
This is a library for using the Flickr API at the Flickr Foundation.
It's not a general-purpose Flickr API library. It provides a subset of Flickr API methods with the following goals:
- Provide reusable code that can be called across all our projects.
- Keep all the details of dealing with the Flickr API in one place.
- Apply types to all results, so the Flickr API can be used safely in a typed context.
Design
Using the Flickr API is fairly simple: you make an HTTP GET to https://api.flickr.com/services/rest/?api_key={api_key} and pass one or more URL query parameters.
One of those query parameters must be method, then you add other parameters depending on the API method.
There's an abstract class that represents this interface:
import abc
from xml.etree import ElementTree as ET
class FlickrApi(abc.ABC):
@abc.abstractmethod
def call(self, method: str, params: dict[str, str] | None = None) -> ET.Element:
return NotImplemented
The idea is that you can extend this class with "method" classes that wrap specific API methods, and make HTTP GET calls through this call() method:
class GetSinglePhotoMethods(FlickrApi):
def get_single_photo(self, photo_id: str) -> ET.Element:
return self.call(method="flickr.photos.getInfo", params={"photo_id": photo_id})
This separates the code for making HTTP requests and separating the responses.
The library includes a single implementation of FlickrApi for making HTTP requests, using httpx, but you could swap it out if you wanted to use e.g. requests or urllib3.
This httpx implementation is the default implementation.
Examples
>>> from flickr_api import FlickrApi
>>> api = FlickrApi.with_api_key(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
FlickrApi.There are two approaches you can use:
-
You can make unauthenticated requests by passing a Flickr API key in the headers:
import httpx client = httpx.Client(params={"api_key": api_key}) api = FlickrApi(cleint)
-
You can make authenticated requests by using OAuth 1.0a:
from authlib.integrations.httpx_client import OAuth1Client client=OAuth1Client( client_id=client_id, client_secret=client_secret, token=token, token_secret=token_secret, ) api = FlickrApi(client)
-
-
Call methods on FlickrApi. There's no complete list of methods right now; look at the files
X_methods.pyin theapidirectory.Methods that return collections of photos also support
pageandper_pageparameters 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.
Metadata
Release files for flickr-photos-api 3.13.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flickr_photos_api-3.13.0.tar.gz | 42.6 kB | Without provenance | Details for flickr_photos_api-3.13.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flickr_photos_api-3.13.0-py3-none-any.whl | Python 3 | none | any | Details for flickr_photos_api-3.13.0-py3-none-any.whl |
Total release size: 86.5 kB
Release files / flickr_photos_api-3.13.0.tar.gz
| Download URL | flickr_photos_api-3.13.0.tar.gz |
|---|---|
| Size | 42.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
041cf36fc8f8e4056cc1a5c8fe180578db5f8504b3936d55f832e792df6eb260
|
|
BLAKE2b-256 checksum How to use checksums |
c17aab61b6a66e6a7eba9933d42a5cd33bbadb37c57f13a190910acd75f4a873
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / flickr_photos_api-3.13.0-py3-none-any.whl
| Download URL | flickr_photos_api-3.13.0-py3-none-any.whl |
|---|---|
| Size | 44.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5aa2d16c819d34d5b34e27bfed5e6f16d6c5868cfce7b2de993d018bd947990d
|
|
BLAKE2b-256 checksum How to use checksums |
2acdca5885702bc3cccf9b394f865a1948d272bad354a3e675052732d1ddd721
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Security for flickr-photos-api 3.13.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.