Name | pystagram JSON |
Version |
1.2.0
JSON |
| download |
home_page | |
Summary | API wrapper for Instagram APIs |
upload_time | 2024-03-16 22:18:43 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.8 |
license | MIT License Copyright (c) 2024 Matthieu THIBAUT Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
api
basic-display-api
facebook
graph-api
instagram
instagram-api
meta
pystagram
wrapper
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
===========
Pystagram
===========
.. image:: https://raw.githubusercontent.com/MatthieuThib/pystagram/main/logo.svg
:target: https://github.com/MatthieuThib/pystagram/
:alt: Pystagram logo
:align: right
:width: 30%
`Home <https://github.com/MatthieuThib/pystagram>`_
• `Docs <https://readthedocs.org/projects/pystagram/>`_
• `PyPi <https://pypi.org/project/pystagram/>`_
• `Features`_
• `Installation`_
• `Usage`_
• `Contributors`_
|Python Version| |Tag| |GitHub Release| |PyPI| |PyPI Downloads| |Wheel| |GitHub Package| |DockerHub| |License|
**Pystagram** is a python client for Instagram APIs.
It provides a simple and easy to use interface for accessing endpoints of both `Graph <https://developers.facebook.com/docs/instagram-api>`_ and `Basic Display <https://developers.facebook.com/docs/instagram-basic-display-api>`_ APIs.
Features
=========
* Instagram Graph API:
* get and publish instagram media (posts, stories, reels)
* manage and reply to comments
* perform hashtag searches
* get metrics about Instagram Businesses and Creators.
* Instagram Basic Display API:
* get user profile information
* get user media
Installation
=============
PyPI (Python)
--------------
|PyPI|
.. code-block:: bash
pip install pystagram
Source Code (Github)
---------------------
|GitHub Release|
.. code-block:: bash
git clone https://github.com/MatthieuThib/pystagram.git
cd pystagram
pip install .
Usage
======
Setup account
--------------
In order to use the Instagram APIs (Graph API and Basic Display API), some prerequisites are required, follow the getting started guide to set up your account and get the necessary credentials:
* `Graph API <https://developers.facebook.com/docs/instagram-api/getting-started>`_
* `Basic Display API <https://developers.facebook.com/docs/instagram-basic-display-api/getting-started>`_
This will provide you with the following credentials:
* App ID
* App Secret
* Access Token
Instagram APIs use access tokens to authenticate requests. Those tokens are tied to specific permissions and can be generated for different purposes.
Before calling any endpoint, make sure that the access token has the necessary permissions to request the endpoint.
See the `Permissions <https://developers.facebook.com/docs/permissions>`_ page for more information.
Code examples
--------------
Instagram Graph API
^^^^^^^^^^^^^^^^^^^^
**Publishing a media**
.. code-block:: python
import os
# Importing the necessary modules
from pystagram import PystagramGraphApi
from pystagram.components.containers import ImageContainer
# Initializing the PystagramGraphApi with the necessary credentials
graph_api = PystagramGraphApi(
app_id=int(os.getenv("APP_ID")), # The App ID from the environment variables
app_secret=os.getenv("APP_SECRET"), # The App Secret from the environment variables
access_token=os.getenv("ACCESS_TOKEN"), # The Access Token from the environment variables
)
# Creating an ImageContainer with the image URL and caption
container = ImageContainer(
image_url="https://www.example.com/image.jpg", # The URL of the image
caption="your caption #hashtag", # The caption for the image
# Additional parameters can be added here
)
# Creating a media object with the ImageContainer
response = graph_api.user.media.create(container)
# Extracting the ID of the created media object
container_id = response.data.get("id")
# Publishing the created media object
graph_api.user.media_publish.create(container_id=container_id)
Instagram Basic Display API
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**Fetch user media**
.. code-block:: python
import os
from pystagram import PystagramBasicDisplayApi
from pystagram.components.fields import MediaFields
# Instantiate the PystagramBasicDisplayApi class with the necessary credentials
basic_display_api = PystagramBasicDisplayApi(
app_id=int(os.getenv("APP_ID")), # The App ID from the environment variables
app_secret=os.getenv("APP_SECRET"), # The App Secret from the environment variables
access_token=os.getenv("ACCESS_TOKEN"), # The Access Token from the environment variables
)
# Fetch the user's media from the API
# The get() method sends a GET request to the API and returns the response
response = basic_display_api.user.user_media.get()
# Extract the user's media data from the response
user_media = response.data.get("data")
Paginated endpoints
--------------------
Both APIs feature paginated endpoints, which means that the response of a request can be split into multiple pages. The pystagram library handles this by decorating the endpoints' methods with a custom decorator `@cursor_paginated`. When called, the decorated method will iterate over all the pages until there is no more pages to fetch or the maximum number of pages is reached.
By default, the maximum number of pages is set to **None** (ie. no limit), but it can be changed by passing setting the attribute **MAX_PAGES** of the class to a different integer value.
.. code-block:: python
from pystagram import PystagramGraphApi
# Initializing the PystagramGraphApi with the necessary credentials
graph_api = PystagramGraphApi( ... )
# Set the maximum number of pages to fetch from the API
graph_api.MAX_PAGES = 5
# Request a cursor paginated endpoint
response = graph_api.user.media.get()
Contributors
=============
|Contributors|
.. |License| image:: https://img.shields.io/github/license/MatthieuThib/pystagram?color=blue
:target: https://opensource.org/licenses/MIT
:alt: License
.. |GitHub Release| image:: https://img.shields.io/badge/github-release-blue?logo=GitHub
:target: https://github.com/MatthieuThib/pystagram/releases/latest
:alt: GitHub Release
.. |Python Version| image:: https://img.shields.io/pypi/pyversions/pystagram
:target: https://pypi.org/project/pystagram
:alt: Python Version
.. |Tag| image:: https://img.shields.io/github/v/tag/MatthieuThib/pystagram
:target: https://github.com/MatthieuThib/pystagram/tags
:alt: Python Version
.. |PyPI| image:: https://img.shields.io/pypi/v/pystagram.svg?label=pip&logo=PyPI&logoColor=white
:target: https://pypi.org/project/pystagram
:alt: PyPI
.. |PyPI Downloads| image:: https://img.shields.io/pypi/dm/pystagram.svg?color=blue&label=Downloads&logo=pypi&logoColor=gold
:target: https://pypi.org/project/pystagram
:alt: PyPI Downloads
.. |GitHub Package| image:: https://img.shields.io/badge/github-package-blue?logo=GitHub
:target: https://github.com/MatthieuThib/pystagram/pkgs/container/pystagram
:alt: GitHub Package
.. |DockerHub| image:: https://img.shields.io/badge/dockerhub-image-blue?logo=Docker
:target: https://hub.docker.com/repository/docker/matthieuthib/pystagram/general
:alt: GitHub Package
.. |Wheel| image:: https://img.shields.io/pypi/wheel/pystagram?color=blue
:target: https://pypi.org/project/pystagram
:alt: PyPI
.. |Contributors| image:: https://contrib.rocks/image?repo=MatthieuThib/pystagram
:target: https://github.com/MatthieuThib/pystagram/graphs/contributors
:alt: Contributors
Raw data
{
"_id": null,
"home_page": "",
"name": "pystagram",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "api,basic-display-api,facebook,graph-api,instagram,instagram-api,meta,pystagram,wrapper",
"author": "",
"author_email": "Matthieu THIBAUT <matthieu_thibaut@icloud.com>",
"download_url": "https://files.pythonhosted.org/packages/73/44/c024b1479084983fbe7fdebaf1bfb818be7a60ca229183781860fc27d5b4/pystagram-1.2.0.tar.gz",
"platform": null,
"description": "===========\n Pystagram\n===========\n\n.. image:: https://raw.githubusercontent.com/MatthieuThib/pystagram/main/logo.svg\n :target: https://github.com/MatthieuThib/pystagram/\n :alt: Pystagram logo\n :align: right\n :width: 30%\n\n\n`Home <https://github.com/MatthieuThib/pystagram>`_\n\u2022 `Docs <https://readthedocs.org/projects/pystagram/>`_\n\u2022 `PyPi <https://pypi.org/project/pystagram/>`_\n\u2022 `Features`_\n\u2022 `Installation`_\n\u2022 `Usage`_\n\u2022 `Contributors`_\n\n|Python Version| |Tag| |GitHub Release| |PyPI| |PyPI Downloads| |Wheel| |GitHub Package| |DockerHub| |License|\n\n\n**Pystagram** is a python client for Instagram APIs.\n\nIt provides a simple and easy to use interface for accessing endpoints of both `Graph <https://developers.facebook.com/docs/instagram-api>`_ and `Basic Display <https://developers.facebook.com/docs/instagram-basic-display-api>`_ APIs.\n\n\nFeatures\n=========\n\n* Instagram Graph API:\n * get and publish instagram media (posts, stories, reels)\n * manage and reply to comments\n * perform hashtag searches\n * get metrics about Instagram Businesses and Creators.\n\n* Instagram Basic Display API:\n * get user profile information\n * get user media\n\n\nInstallation\n=============\n\nPyPI (Python)\n--------------\n\n|PyPI|\n\n.. code-block:: bash\n\n pip install pystagram\n\nSource Code (Github)\n---------------------\n\n|GitHub Release|\n\n.. code-block:: bash\n\n git clone https://github.com/MatthieuThib/pystagram.git\n cd pystagram\n pip install .\n\n\nUsage\n======\n\nSetup account\n--------------\n\nIn order to use the Instagram APIs (Graph API and Basic Display API), some prerequisites are required, follow the getting started guide to set up your account and get the necessary credentials:\n\n* `Graph API <https://developers.facebook.com/docs/instagram-api/getting-started>`_\n* `Basic Display API <https://developers.facebook.com/docs/instagram-basic-display-api/getting-started>`_\n\nThis will provide you with the following credentials:\n\n* App ID\n* App Secret\n* Access Token\n\nInstagram APIs use access tokens to authenticate requests. Those tokens are tied to specific permissions and can be generated for different purposes.\nBefore calling any endpoint, make sure that the access token has the necessary permissions to request the endpoint.\n\nSee the `Permissions <https://developers.facebook.com/docs/permissions>`_ page for more information.\n\n\nCode examples\n--------------\n\nInstagram Graph API\n^^^^^^^^^^^^^^^^^^^^\n\n**Publishing a media**\n\n.. code-block:: python\n\n import os\n\n # Importing the necessary modules\n from pystagram import PystagramGraphApi\n from pystagram.components.containers import ImageContainer\n\n # Initializing the PystagramGraphApi with the necessary credentials\n graph_api = PystagramGraphApi(\n app_id=int(os.getenv(\"APP_ID\")), # The App ID from the environment variables\n app_secret=os.getenv(\"APP_SECRET\"), # The App Secret from the environment variables\n access_token=os.getenv(\"ACCESS_TOKEN\"), # The Access Token from the environment variables\n )\n\n # Creating an ImageContainer with the image URL and caption\n container = ImageContainer(\n image_url=\"https://www.example.com/image.jpg\", # The URL of the image\n caption=\"your caption #hashtag\", # The caption for the image\n # Additional parameters can be added here\n )\n\n # Creating a media object with the ImageContainer\n response = graph_api.user.media.create(container)\n # Extracting the ID of the created media object\n container_id = response.data.get(\"id\")\n\n # Publishing the created media object\n graph_api.user.media_publish.create(container_id=container_id)\n\n\n\nInstagram Basic Display API\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n**Fetch user media**\n\n.. code-block:: python\n\n import os\n\n from pystagram import PystagramBasicDisplayApi\n from pystagram.components.fields import MediaFields\n\n # Instantiate the PystagramBasicDisplayApi class with the necessary credentials\n basic_display_api = PystagramBasicDisplayApi(\n app_id=int(os.getenv(\"APP_ID\")), # The App ID from the environment variables\n app_secret=os.getenv(\"APP_SECRET\"), # The App Secret from the environment variables\n access_token=os.getenv(\"ACCESS_TOKEN\"), # The Access Token from the environment variables\n )\n\n # Fetch the user's media from the API\n # The get() method sends a GET request to the API and returns the response\n response = basic_display_api.user.user_media.get()\n\n # Extract the user's media data from the response\n user_media = response.data.get(\"data\")\n\n\nPaginated endpoints\n--------------------\n\nBoth APIs feature paginated endpoints, which means that the response of a request can be split into multiple pages. The pystagram library handles this by decorating the endpoints' methods with a custom decorator `@cursor_paginated`. When called, the decorated method will iterate over all the pages until there is no more pages to fetch or the maximum number of pages is reached.\nBy default, the maximum number of pages is set to **None** (ie. no limit), but it can be changed by passing setting the attribute **MAX_PAGES** of the class to a different integer value.\n\n.. code-block:: python\n\n from pystagram import PystagramGraphApi\n\n # Initializing the PystagramGraphApi with the necessary credentials\n graph_api = PystagramGraphApi( ... )\n\n # Set the maximum number of pages to fetch from the API\n graph_api.MAX_PAGES = 5\n\n # Request a cursor paginated endpoint\n response = graph_api.user.media.get()\n\n\nContributors\n=============\n\n|Contributors|\n\n.. |License| image:: https://img.shields.io/github/license/MatthieuThib/pystagram?color=blue\n :target: https://opensource.org/licenses/MIT\n :alt: License\n\n.. |GitHub Release| image:: https://img.shields.io/badge/github-release-blue?logo=GitHub\n :target: https://github.com/MatthieuThib/pystagram/releases/latest\n :alt: GitHub Release\n\n.. |Python Version| image:: https://img.shields.io/pypi/pyversions/pystagram\n :target: https://pypi.org/project/pystagram\n :alt: Python Version\n\n.. |Tag| image:: https://img.shields.io/github/v/tag/MatthieuThib/pystagram\n :target: https://github.com/MatthieuThib/pystagram/tags\n :alt: Python Version\n\n.. |PyPI| image:: https://img.shields.io/pypi/v/pystagram.svg?label=pip&logo=PyPI&logoColor=white\n :target: https://pypi.org/project/pystagram\n :alt: PyPI\n\n.. |PyPI Downloads| image:: https://img.shields.io/pypi/dm/pystagram.svg?color=blue&label=Downloads&logo=pypi&logoColor=gold\n :target: https://pypi.org/project/pystagram\n :alt: PyPI Downloads\n\n.. |GitHub Package| image:: https://img.shields.io/badge/github-package-blue?logo=GitHub\n :target: https://github.com/MatthieuThib/pystagram/pkgs/container/pystagram\n :alt: GitHub Package\n\n.. |DockerHub| image:: https://img.shields.io/badge/dockerhub-image-blue?logo=Docker\n :target: https://hub.docker.com/repository/docker/matthieuthib/pystagram/general\n :alt: GitHub Package\n\n.. |Wheel| image:: https://img.shields.io/pypi/wheel/pystagram?color=blue\n :target: https://pypi.org/project/pystagram\n :alt: PyPI\n\n.. |Contributors| image:: https://contrib.rocks/image?repo=MatthieuThib/pystagram\n :target: https://github.com/MatthieuThib/pystagram/graphs/contributors\n :alt: Contributors",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Matthieu THIBAUT Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "API wrapper for Instagram APIs",
"version": "1.2.0",
"project_urls": {
"Documentation": "https://pystagram.readthedocs.io/en/latest/",
"Homepage": "https://github.com/MatthieuThib/pystagram",
"Issues": "https://github.com/MatthieuThib/pystagram/issues",
"Source": "https://github.com/MatthieuThib/pystagram"
},
"split_keywords": [
"api",
"basic-display-api",
"facebook",
"graph-api",
"instagram",
"instagram-api",
"meta",
"pystagram",
"wrapper"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b8fefaac4988864a3057d569d33ea2c893dd014c8a7f30d4196100b9a87a103c",
"md5": "a57746b0ed03dabca3fb3c2337680ec0",
"sha256": "684b8f8bfb5679d81aa4d4e247dd41545415e83a93cce12c166f1f90fbdb8340"
},
"downloads": -1,
"filename": "pystagram-1.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a57746b0ed03dabca3fb3c2337680ec0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 76395,
"upload_time": "2024-03-16T22:18:41",
"upload_time_iso_8601": "2024-03-16T22:18:41.095006Z",
"url": "https://files.pythonhosted.org/packages/b8/fe/faac4988864a3057d569d33ea2c893dd014c8a7f30d4196100b9a87a103c/pystagram-1.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7344c024b1479084983fbe7fdebaf1bfb818be7a60ca229183781860fc27d5b4",
"md5": "dad58616613355491261387632a9e7d2",
"sha256": "8c82cc99fa904a15c6f93d08bc73371a113d74004aafcae3dc5dff5d54ae8619"
},
"downloads": -1,
"filename": "pystagram-1.2.0.tar.gz",
"has_sig": false,
"md5_digest": "dad58616613355491261387632a9e7d2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 3334568,
"upload_time": "2024-03-16T22:18:43",
"upload_time_iso_8601": "2024-03-16T22:18:43.195492Z",
"url": "https://files.pythonhosted.org/packages/73/44/c024b1479084983fbe7fdebaf1bfb818be7a60ca229183781860fc27d5b4/pystagram-1.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-16 22:18:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "MatthieuThib",
"github_project": "pystagram",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pystagram"
}