flickr-photos-api


Nameflickr-photos-api JSON
Version 2.16.1 PyPI version JSON
download
home_pageNone
SummaryLook up information about photos and collections of photos from Flickr
upload_time2025-02-21 13:32:43
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseNone
keywords flickr
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.
*   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.

[Flickr Foundation]: https://www.flickr.org/

## 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:

```python
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:

```python
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

```console
>>> from flickr_photos_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

1.  Install flickr-photos-api from PyPI:

    ```console
    $ pip install flickr-photos-api
    ```

2.  Construct an instance of `FlickrApi`.

    There are two approaches you can use:

    *   You can make unauthenticated requests by passing a [Flickr API key][key] in the headers:

        ```python
        import httpx

        client = httpx.Client(params={"api_key": api_key})

        api = FlickrApi(cleint)
        ```

    *   You can make authenticated requests by using OAuth 1.0a:

        ```python
        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)
        ```

3.  Call methods on FlickrApi.
    There's no complete list of methods right now; look at the files `X_methods.py` in the `api` directory.

    Methods that return collections of photos also support `page` and `per_page` parameters to control pagination.

[key]: https://www.flickr.com/services/api/misc.api_keys.html

## Development

If you want to make changes to the library, there are instructions in [CONTRIBUTING.md](./CONTRIBUTING.md).

## License

This project is dual-licensed as Apache-2.0 and MIT.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "flickr-photos-api",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": "Alex Chan <alex@flickr.org>",
    "keywords": "flickr",
    "author": null,
    "author_email": "Flickr Foundation <hello@flickr.org>",
    "download_url": "https://files.pythonhosted.org/packages/df/ae/e8b83c66b8f5067484556c6a05d67725478b3d28b73afd663cd031b1bbff/flickr_photos_api-2.16.1.tar.gz",
    "platform": null,
    "description": "# flickr-photos-api\n\nThis is a library for using the Flickr API at the [Flickr Foundation].\n\nIt's *not* a general-purpose Flickr API library.\nIt provides a subset of Flickr API methods with the following goals:\n\n*   Provide reusable code that can be called across all our projects.\n*   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.\n*   Apply types to all results, so the Flickr API can be used safely in a typed context.\n\n[Flickr Foundation]: https://www.flickr.org/\n\n## Design\n\nUsing 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.\nOne of those query parameters must be `method`, then you add other parameters depending on the API method.\n\nThere's an abstract class that represents this interface:\n\n```python\nimport abc\nfrom xml.etree import ElementTree as ET\n\n\nclass FlickrApi(abc.ABC):\n    @abc.abstractmethod\n    def call(self, method: str, params: dict[str, str] | None = None) -> ET.Element:\n        return NotImplemented\n```\n\nThe 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:\n\n```python\nclass GetSinglePhotoMethods(FlickrApi):\n    def get_single_photo(self, photo_id: str) -> ET.Element:\n        return self.call(method=\"flickr.photos.getInfo\", params={\"photo_id\": photo_id})\n```\n\nThis separates the code for making HTTP requests and separating the responses.\n\nThe 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`.\nThis httpx implementation is the default implementation.\n\n## Examples\n\n```console\n>>> from flickr_photos_api import FlickrApi\n>>> api = FlickrApi.with_api_key(api_key=\"\u2026\", user_agent=\"\u2026\")\n\n>>> photo = api.get_single_photo(photo_id=\"14898030836\")\n\n>>> photo\n{'id': '14898030836', 'title': 'NASA Scientists Says', \u2026}\n\n>>> photo[\"license\"]\n{'id': 'cc-by-2.0', 'label': 'CC BY 2.0', 'url': 'https://creativecommons.org/licenses/by/2.0/'}\n\n>>> photo[\"url\"]\n'https://www.flickr.com/photos/lassennps/14898030836/'\n```\n\n## Usage\n\n1.  Install flickr-photos-api from PyPI:\n\n    ```console\n    $ pip install flickr-photos-api\n    ```\n\n2.  Construct an instance of `FlickrApi`.\n\n    There are two approaches you can use:\n\n    *   You can make unauthenticated requests by passing a [Flickr API key][key] in the headers:\n\n        ```python\n        import httpx\n\n        client = httpx.Client(params={\"api_key\": api_key})\n\n        api = FlickrApi(cleint)\n        ```\n\n    *   You can make authenticated requests by using OAuth 1.0a:\n\n        ```python\n        from authlib.integrations.httpx_client import OAuth1Client\n\n        client=OAuth1Client(\n            client_id=client_id,\n            client_secret=client_secret,\n            token=token,\n            token_secret=token_secret,\n        )\n\n        api = FlickrApi(client)\n        ```\n\n3.  Call methods on FlickrApi.\n    There's no complete list of methods right now; look at the files `X_methods.py` in the `api` directory.\n\n    Methods that return collections of photos also support `page` and `per_page` parameters to control pagination.\n\n[key]: https://www.flickr.com/services/api/misc.api_keys.html\n\n## Development\n\nIf you want to make changes to the library, there are instructions in [CONTRIBUTING.md](./CONTRIBUTING.md).\n\n## License\n\nThis project is dual-licensed as Apache-2.0 and MIT.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Look up information about photos and collections of photos from Flickr",
    "version": "2.16.1",
    "project_urls": {
        "Changelog": "https://github.com/Flickr-Foundation/flickr-photos-api/blob/main/CHANGELOG.md",
        "Homepage": "https://github.com/Flickr-Foundation/flickr-photos-api"
    },
    "split_keywords": [
        "flickr"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7c334a073468ac89cfa9173de1100cf02d58b4905605a8d72f1b33ffb9bdd041",
                "md5": "7890b314c8cc4c32a2aff044fab52a67",
                "sha256": "2f8c7b929b3380b474337c3021a73e4381b47b7ea04c0b6bc9e696addcd000f3"
            },
            "downloads": -1,
            "filename": "flickr_photos_api-2.16.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7890b314c8cc4c32a2aff044fab52a67",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 39182,
            "upload_time": "2025-02-21T13:32:41",
            "upload_time_iso_8601": "2025-02-21T13:32:41.743851Z",
            "url": "https://files.pythonhosted.org/packages/7c/33/4a073468ac89cfa9173de1100cf02d58b4905605a8d72f1b33ffb9bdd041/flickr_photos_api-2.16.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dfaee8b83c66b8f5067484556c6a05d67725478b3d28b73afd663cd031b1bbff",
                "md5": "48ddb2edb98d1a3ea8a82596f6db2aba",
                "sha256": "98af566a3ebc5074cd8a9b49a637e3b56c36c4a3f25f65748d2a124aeaaeb031"
            },
            "downloads": -1,
            "filename": "flickr_photos_api-2.16.1.tar.gz",
            "has_sig": false,
            "md5_digest": "48ddb2edb98d1a3ea8a82596f6db2aba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 36923,
            "upload_time": "2025-02-21T13:32:43",
            "upload_time_iso_8601": "2025-02-21T13:32:43.274802Z",
            "url": "https://files.pythonhosted.org/packages/df/ae/e8b83c66b8f5067484556c6a05d67725478b3d28b73afd663cd031b1bbff/flickr_photos_api-2.16.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-21 13:32:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Flickr-Foundation",
    "github_project": "flickr-photos-api",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "flickr-photos-api"
}
        
Elapsed time: 2.58464s