1
0
mirror of https://github.com/instaloader/instaloader.git synced 2024-11-04 09:22:29 +01:00
instaloader/docs/as-module.rst

117 lines
3.4 KiB
ReStructuredText
Raw Normal View History

.. meta::
:description:
Instaloader can also be used as a powerful and easy-to-use
Python API for Instagram, allowing to download media and metadata.
2017-09-08 10:35:38 +02:00
Python Module :mod:`instaloader`
--------------------------------
2017-09-08 10:35:38 +02:00
.. module:: instaloader
2017-09-08 10:35:38 +02:00
.. highlight:: python
Instaloader exposes its internally used methods as a Python module, making it a
**powerful and easy-to-use Python API for Instagram**, allowing to further
customize obtaining media and metadata.
2017-09-08 10:35:38 +02:00
Start with getting an instance of :class:`Instaloader`::
2017-09-08 10:35:38 +02:00
import instaloader
# Get instance
L = instaloader.Instaloader()
# Optionally, login or load session
L.login(USER, PASSWORD) # (login)
L.interactive_login(USER) # (ask password on terminal)
L.load_session_from_file(USER) # (load session created w/
# `instaloader -l USERNAME`)
:mod:`instaloader` provides the :class:`Post` structure, which represents a
picture, video or sidecar (set of multiple pictures/videos) posted in a user's
profile. :class:`Instaloader` provides methods to iterate over Posts from a
certain source::
for post in L.get_hashtag_posts('cat'):
# post is an instance of instaloader.Post
L.download_post(post, target='#cat')
2017-09-08 10:35:38 +02:00
Besides :func:`Instaloader.get_hashtag_posts`, there is
:func:`Instaloader.get_feed_posts` and :func:`Instaloader.get_profile_posts`.
Also, :class:`Post` instances can be created with :func:`Post.from_shortcode`
and :func:`Post.from_mediaid`.
Further, information about profiles can be easily obtained. For example, you may
print a list of all followees and followers of a profile with::
2017-09-08 10:35:38 +02:00
# Print followees
print(PROFILE + " follows these profiles:")
for f in L.get_followees(PROFILE):
2017-09-08 10:35:38 +02:00
print("\t%s\t%s" % (f['username'], f['full_name']))
# Print followers
print("Followers of " + PROFILE + ":")
for f in L.get_followers(PROFILE):
2017-09-08 10:35:38 +02:00
print("\t%s\t%s" % (f['username'], f['full_name']))
Then, you may download all pictures of all followees with::
2017-09-08 10:35:38 +02:00
for f in L.get_followees(PROFILE):
L.download_profile(f['username'])
2017-09-08 10:35:38 +02:00
Each Instagram profile has its own unique ID which stays unmodified even if a
user changes his/her username. To get said ID, given the profile's name, you may
call::
2017-09-08 10:35:38 +02:00
L.get_id_by_username(PROFILE_NAME)
A reference of the many methods provided by the :mod:`instaloader` module is
provided in the remainder of this document. Feel free to direct any issue or
contribution to
`Instaloader on Github <https://github.com/instaloader/instaloader>`__.
``Instaloader`` (Main Class)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2017-09-08 10:35:38 +02:00
.. autoclass:: Instaloader
:no-show-inheritance:
``Post`` Class
^^^^^^^^^^^^^^
2017-09-08 10:35:38 +02:00
.. autoclass:: Post
:no-show-inheritance:
Miscellaneous Functions
^^^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: shortcode_to_mediaid
.. autofunction:: mediaid_to_shortcode
.. autoclass:: Tristate
Exceptions
^^^^^^^^^^
.. autoexception:: InstaloaderException
:no-show-inheritance:
.. autoexception:: QueryReturnedNotFoundException
.. autoexception:: ProfileNotExistsException
.. autoexception:: ProfileHasNoPicsException
.. autoexception:: PrivateProfileNotFollowedException
.. autoexception:: LoginRequiredException
.. autoexception:: InvalidArgumentException
.. autoexception:: BadResponseException
.. autoexception:: BadCredentialsException
.. autoexception:: ConnectionException