Skip to content

diezo/Ensta

Repository files navigation

Ensta - Simple Instagram API

PyPI PyPI - Python Version Downloads

Logo

Ensta is a simple, reliable and up-to-date python package for Instagram API.

Both authenticated and anonymous requests are supported.

Show Your Support! 🌟

If Ensta could add value to your projects, please do give this repo a star. Thanks!

Installation

Read the pre-requisites here.

pip install ensta

Example

Fetching profile info by username:

from ensta import Mobile

mobile = Mobile(username, password)

profile = mobile.profile("leomessi")

print(profile.full_name)
print(profile.biography)
print(profile.profile_pic_url)

Features

These features use the Mobile API.

Using Proxies

When to use a proxy:

  • You're being rate limited.
  • Ensta is not working because your Home IP is flagged.
  • You're deploying Ensta to the cloud. (Instagram blocks requests from IPs of cloud providers, so a proxy must be used)
from ensta import Mobile

mobile = Mobile(
    username,
    password,
    proxy={
        "http": "socks5://username:password@host:port",
        "https": "socks5://username:password@host:port"
    }
)

Ensta uses the same proxy settings as the requests module.

Username-Password Login

Username is recommended to sign in. However, email can also be used.

from ensta import Mobile

# Recommended
mobile = Mobile(username, password)

# This also works
mobile = Mobile(email, password)
Change Profile Picture
from ensta import Mobile

mobile = Mobile(username, password)

mobile.change_profile_picture("image.jpg")
Fetch Profile Information
from ensta import Mobile

mobile = Mobile(username, password)

profile = mobile.profile("leomessi")

print(profile.full_name)
print(profile.biography)
print(profile.follower_count)
Follow/Unfollow Account
from ensta import Mobile

mobile = Mobile(username, password)

mobile.follow("leomessi")
mobile.unfollow("leomessi")
Change Biography
from ensta import Mobile

mobile = Mobile(username, password)

mobile.change_biography("New bio here.")
Switch to Private/Public Account
from ensta import Mobile

mobile = Mobile(username, password)

mobile.switch_to_private_account()
mobile.switch_to_public_account()
Username to UserID / UserID to Username
from ensta import Mobile

mobile = Mobile(username, password)

mobile.username_to_userid("leomessi")
mobile.userid_to_username("12345678")
Like/Unlike Post
from ensta import Mobile

mobile = Mobile(username, password)

mobile.like(media_id)
mobile.unlike(media_id)
Fetch Followers/Followings
from ensta import Mobile

mobile = Mobile(username, password)

followers = mobile.followers("leomessi")
followings = mobile.followings("leomessi")

for user in followers.list:
    print(user.full_name)

for user in followings.list:
    print(user.full_name)

# Fetching next chunk
followers = mobile.followers(
    "leomessi",
    next_cursor=followers.next_cursor
)
Add Comment to Post
from ensta import Mobile

mobile = Mobile(username, password)

mobile.comment("Hello", media_id)
Upload Photo
from ensta import Mobile

mobile = Mobile(username, password)

mobile.upload_photo(
    upload_id=upload_id,
    caption="Hello"
)
Upload Sidecar (Multiple Photos)
from ensta import Mobile
from ensta.structures import SidecarChild

mobile = Mobile(username, password)

mobile.upload_sidecar(
    children=[
        SidecarChild(uploda_id),
        SidecarChild(uploda_id),
        SidecarChild(uploda_id)
    ],
    caption="Hello"
)
Fetch Private Information (Yours)
from ensta import Mobile

mobile = Mobile(username, password)

account = mobile.private_info()

print(account.email)
print(account.account_type)
print(account.phone_number)
Update Display Name
from ensta import Mobile

mobile = Mobile(username, password)

mobile.update_display_name("Lionel Messi")
Block/Unblock User
from ensta import Mobile

mobile = Mobile(username, password)

mobile.block(123456789)  # Use UserID
mobile.unblock(123456789)  # Use UserID
Upload Story (Photo)
from ensta import Mobile

mobile = Mobile(username, password)

upload_id = mobile.get_upload_id("image.jpg")

mobile.upload_story(upload_id)
Upload Story (Photo) + Link Sticker
from ensta import Mobile
from ensta.structures import StoryLink

mobile = Mobile(username, password)

upload_id = mobile.get_upload_id("image.jpg")

mobile.upload_story(upload_id, entities=[
    StoryLink(title="Google", url="https://google.com")
])
Send Message (Text)
from ensta import Mobile

mobile = Mobile(username, password)  # Or use email
direct = mobile.direct()

direct.send_text("Hello", thread_id)
Send Message (Picture)
from ensta import Mobile

mobile = Mobile(username, password)  # Or use email
direct = mobile.direct()

media_id = direct.fb_upload_image("image.jpg")

direct.send_photo(media_id, thread_id)
Add Biography Link
from ensta import Mobile

mobile = Mobile(username, password)  # Or use email

link_id = mobile.add_bio_link(
    url="https://github.com/diezo",
    title="Diezo's GitHub"
)
Add Multiple Biography Links
from ensta import Mobile
from ensta.structures import BioLink

mobile = Mobile(username, password)  # Or use email

link_ids = mobile.add_bio_links([
    BioLink(url="https://example.com", title="Link 1"),
    BioLink(url="https://example.com", title="Link 2"),
    BioLink(url="https://example.com", title="Link 3")
])
Remove Biography Link
from ensta import Mobile

mobile = Mobile(username, password)  # Or use email

mobile.remove_bio_link(link_id)
Remove Multiple Biography Links
from ensta import Mobile

mobile = Mobile(username, password)  # Or use email

mobile.remove_bio_links([
    link_id_1,
    link_id_2,
    link_id_3
])
Clear All Biography Links
from ensta import Mobile

mobile = Mobile(username, password)  # Or use email

mobile.clear_bio_links()

Deprecated Features (Web API)

Features still using the Web API:

Upload Reel
from ensta import Web

host = Web(username, password)

video_id = host.upload_video_for_reel("Video.mp4", thumbnail="Thumbnail.jpg")

host.pub_reel(
    video_id,
    caption="Enjoying the winter! β›„"
)
Fetch Web Profile Data
from ensta import Web

host = Web(username, password)
profile = host.profile("leomessi")

print(profile.full_name)
print(profile.biography)
print(profile.follower_count)
Fetch Someone's Feed
from ensta import Web

host = Web(username, password)
posts = host.posts("leomessi", 100)  # Want full list? Set count to '0'

for post in posts:
    print(post.caption_text)
    print(post.like_count)    
Fetch Post's Likers
from ensta import Web

host = Web(username, password)

post_id = host.get_post_id("https://www.instagram.com/p/Czr2yLmroCQ/")
likers = host.likers(post_id)

for user in likers.users:
    print(user.username)
    print(user.profile_picture_url)

They'll be migrated to the Mobile API soon.

Supported Classes

Important

The Web Class is deprecated and it's features are being migrated to the Mobile Class. It'll be removed from Ensta upon completion.


Mobile Class (Authenticated)

Requires login, and has the most features.

from ensta import Mobile

mobile = Mobile(username, password)
profile = mobile.profile("leomessi")

print(profile.full_name)
print(profile.biography)
print(profile.profile_pic_url)

Guest Class (Non-Authenticated)

Doesn't require login, but has limited features.

from ensta import Guest

guest = Guest()
profile = guest.profile("leomessi")

print(profile.biography)

Web Class (Authenticated) (Deprecated)
from ensta import Web

host = Web(username, password)
profile = host.profile("leomessi")

print(profile.biography)

Discord Community

Ask questions, discuss upcoming features and meet other developers.

Buy Me A Coffee

Support me in the development of this project.

Contributors

Contributors

Disclaimer

This is a third party library and not associated with Instagram. We're strictly against spam. You are liable for all the actions you take.