instapost 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- instapost/__init__.py +22 -0
- instapost/api/__init__.py +3 -0
- instapost/api/base.py +83 -0
- instapost/client.py +118 -0
- instapost/exceptions.py +13 -0
- instapost/media/__init__.py +3 -0
- instapost/media/uploader.py +115 -0
- instapost/posting/__init__.py +5 -0
- instapost/posting/carousel.py +52 -0
- instapost/posting/image.py +22 -0
- instapost/posting/reel.py +52 -0
- instapost-0.1.0.dist-info/METADATA +140 -0
- instapost-0.1.0.dist-info/RECORD +15 -0
- instapost-0.1.0.dist-info/WHEEL +4 -0
- instapost-0.1.0.dist-info/licenses/LICENSE +21 -0
instapost/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from .exceptions import (
|
|
2
|
+
InstagramAPIError,
|
|
3
|
+
ContainerProcessingError,
|
|
4
|
+
ContainerTimeoutError,
|
|
5
|
+
)
|
|
6
|
+
from .api.base import BaseInstagramClient
|
|
7
|
+
from .posting.image import ImagePoster
|
|
8
|
+
from .posting.reel import ReelPoster
|
|
9
|
+
from .posting.carousel import CarouselPoster
|
|
10
|
+
from .client import InstagramPoster
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"InstagramPoster",
|
|
14
|
+
"ImagePoster",
|
|
15
|
+
"ReelPoster",
|
|
16
|
+
"CarouselPoster",
|
|
17
|
+
"BaseInstagramClient",
|
|
18
|
+
"InstagramAPIError",
|
|
19
|
+
"ContainerProcessingError",
|
|
20
|
+
"ContainerTimeoutError",
|
|
21
|
+
]
|
|
22
|
+
__version__ = "0.1.0"
|
instapost/api/base.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import time
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
|
|
5
|
+
from ..exceptions import ContainerProcessingError, ContainerTimeoutError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BaseInstagramClient(ABC):
|
|
9
|
+
"""Base class for Instagram API clients."""
|
|
10
|
+
|
|
11
|
+
BASE_URL = "https://graph.instagram.com"
|
|
12
|
+
|
|
13
|
+
def __init__(self, access_token: str, ig_user_id: str):
|
|
14
|
+
self.access_token = access_token
|
|
15
|
+
self.ig_user_id = ig_user_id
|
|
16
|
+
|
|
17
|
+
def _request(self, method: str, endpoint: str, **kwargs) -> dict:
|
|
18
|
+
"""Make a request to the Graph API."""
|
|
19
|
+
url = f"{self.BASE_URL}/{endpoint}"
|
|
20
|
+
kwargs.setdefault("params", {})["access_token"] = self.access_token
|
|
21
|
+
response = requests.request(method, url, **kwargs)
|
|
22
|
+
response.raise_for_status()
|
|
23
|
+
return response.json()
|
|
24
|
+
|
|
25
|
+
def _create_container(self, params: dict) -> str:
|
|
26
|
+
"""Create a media container and return its ID."""
|
|
27
|
+
result = self._request("POST", "me/media", params=params)
|
|
28
|
+
return result["id"]
|
|
29
|
+
|
|
30
|
+
def _publish_container(self, container_id: str) -> dict:
|
|
31
|
+
"""Publish a media container."""
|
|
32
|
+
return self._request(
|
|
33
|
+
"POST",
|
|
34
|
+
"me/media_publish",
|
|
35
|
+
params={"creation_id": container_id},
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def _wait_for_container(self, container_id: str, timeout: int = 60, interval: int = 5) -> None:
|
|
39
|
+
"""Wait for a media container to finish processing."""
|
|
40
|
+
elapsed = 0
|
|
41
|
+
while elapsed < timeout:
|
|
42
|
+
result = self._request("GET", container_id, params={"fields": "status_code,status"})
|
|
43
|
+
status = result.get("status_code")
|
|
44
|
+
|
|
45
|
+
if status == "FINISHED":
|
|
46
|
+
return
|
|
47
|
+
if status == "ERROR":
|
|
48
|
+
raise ContainerProcessingError(f"Container processing failed: {result.get('status')}")
|
|
49
|
+
|
|
50
|
+
time.sleep(interval)
|
|
51
|
+
elapsed += interval
|
|
52
|
+
|
|
53
|
+
raise ContainerTimeoutError(f"Container {container_id} did not finish processing in {timeout}s")
|
|
54
|
+
|
|
55
|
+
def verify(self) -> dict:
|
|
56
|
+
"""Verify credentials and return account info."""
|
|
57
|
+
return self._request(
|
|
58
|
+
"GET",
|
|
59
|
+
"me",
|
|
60
|
+
params={"fields": "id,username,name"},
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def publish(self, container_id: str) -> dict:
|
|
64
|
+
"""
|
|
65
|
+
Publish a previously uploaded media container.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
container_id: The container ID returned by upload().
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
API response with the published media ID.
|
|
72
|
+
"""
|
|
73
|
+
return self._publish_container(container_id)
|
|
74
|
+
|
|
75
|
+
@abstractmethod
|
|
76
|
+
def upload(self, *args, **kwargs) -> str:
|
|
77
|
+
"""Upload content and return the container ID."""
|
|
78
|
+
pass
|
|
79
|
+
|
|
80
|
+
def post(self, *args, **kwargs) -> dict:
|
|
81
|
+
"""Upload and publish content in one step."""
|
|
82
|
+
container_id = self.upload(*args, **kwargs)
|
|
83
|
+
return self.publish(container_id)
|
instapost/client.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from .api.base import BaseInstagramClient
|
|
5
|
+
from .posting.image import ImagePoster
|
|
6
|
+
from .posting.reel import ReelPoster
|
|
7
|
+
from .posting.carousel import CarouselPoster
|
|
8
|
+
from .media.uploader import MediaUploader
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class InstagramPoster(BaseInstagramClient):
|
|
12
|
+
"""Unified client for posting images, reels, and carousels to Instagram."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, access_token: str, ig_user_id: str):
|
|
15
|
+
super().__init__(access_token, ig_user_id)
|
|
16
|
+
self._image = ImagePoster(access_token, ig_user_id)
|
|
17
|
+
self._reel = ReelPoster(access_token, ig_user_id)
|
|
18
|
+
self._carousel = CarouselPoster(access_token, ig_user_id)
|
|
19
|
+
|
|
20
|
+
def upload(self, *args, **kwargs) -> str:
|
|
21
|
+
"""Upload content. Use upload_image, upload_reel, or upload_carousel for specific types."""
|
|
22
|
+
raise NotImplementedError("Use upload_image, upload_reel, or upload_carousel instead")
|
|
23
|
+
|
|
24
|
+
def post(self, *args, **kwargs) -> dict:
|
|
25
|
+
"""Post content. Use post_image, post_reel, or post_carousel for specific types."""
|
|
26
|
+
raise NotImplementedError("Use post_image, post_reel, or post_carousel instead")
|
|
27
|
+
|
|
28
|
+
# Image methods
|
|
29
|
+
def upload_image(self, image_url: str, caption: str = "") -> str:
|
|
30
|
+
"""Upload a single image and return container ID."""
|
|
31
|
+
return self._image.upload(image_url, caption)
|
|
32
|
+
|
|
33
|
+
def post_image(self, image_url: str, caption: str = "") -> dict:
|
|
34
|
+
"""Upload and publish a single image.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
image_url: URL or local file path to image
|
|
38
|
+
caption: Optional caption
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
API response with published media ID
|
|
42
|
+
"""
|
|
43
|
+
# Auto-upload if local file
|
|
44
|
+
if os.path.exists(image_url):
|
|
45
|
+
image_url = MediaUploader.upload_image(image_url)
|
|
46
|
+
|
|
47
|
+
return self._image.post(image_url, caption)
|
|
48
|
+
|
|
49
|
+
# Reel methods
|
|
50
|
+
def upload_reel(
|
|
51
|
+
self,
|
|
52
|
+
video_url: str,
|
|
53
|
+
caption: str = "",
|
|
54
|
+
cover_url: Optional[str] = None,
|
|
55
|
+
share_to_feed: bool = True,
|
|
56
|
+
timeout: int = 120,
|
|
57
|
+
) -> str:
|
|
58
|
+
"""Upload a reel and return container ID."""
|
|
59
|
+
return self._reel.upload(video_url, caption, cover_url, share_to_feed, timeout)
|
|
60
|
+
|
|
61
|
+
def post_reel(
|
|
62
|
+
self,
|
|
63
|
+
video_url: str,
|
|
64
|
+
caption: str = "",
|
|
65
|
+
cover_url: Optional[str] = None,
|
|
66
|
+
share_to_feed: bool = True,
|
|
67
|
+
timeout: int = 120,
|
|
68
|
+
) -> dict:
|
|
69
|
+
"""Upload and publish a reel.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
video_url: URL or local file path to video
|
|
73
|
+
caption: Optional caption
|
|
74
|
+
cover_url: Optional URL or local path to cover image
|
|
75
|
+
share_to_feed: Whether to also share to feed
|
|
76
|
+
timeout: Video processing timeout in seconds
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
API response with published media ID
|
|
80
|
+
"""
|
|
81
|
+
# Auto-upload if local files
|
|
82
|
+
if os.path.exists(video_url):
|
|
83
|
+
video_url = MediaUploader.upload_video(video_url)
|
|
84
|
+
|
|
85
|
+
if cover_url and os.path.exists(cover_url):
|
|
86
|
+
cover_url = MediaUploader.upload_image(cover_url)
|
|
87
|
+
|
|
88
|
+
return self._reel.post(video_url, caption, cover_url, share_to_feed, timeout)
|
|
89
|
+
|
|
90
|
+
# Carousel methods
|
|
91
|
+
def upload_carousel(self, media_urls: list[dict], caption: str = "") -> str:
|
|
92
|
+
"""Upload a carousel and return container ID."""
|
|
93
|
+
return self._carousel.upload(media_urls, caption)
|
|
94
|
+
|
|
95
|
+
def post_carousel(self, media_urls: list[dict], caption: str = "") -> dict:
|
|
96
|
+
"""Upload and publish a carousel.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
media_urls: List of dicts with 'media' (local file path or publicly accessible URL)
|
|
100
|
+
and 'type' keys. Type must be 'IMAGE' or 'VIDEO'
|
|
101
|
+
caption: Optional caption
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
API response with published media ID
|
|
105
|
+
"""
|
|
106
|
+
# Auto-upload local files
|
|
107
|
+
processed_urls = []
|
|
108
|
+
for item in media_urls:
|
|
109
|
+
media = item['media']
|
|
110
|
+
if os.path.exists(media):
|
|
111
|
+
media = MediaUploader.upload(media)
|
|
112
|
+
|
|
113
|
+
processed_urls.append({
|
|
114
|
+
'media': media,
|
|
115
|
+
'type': item['type']
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
return self._carousel.post(processed_urls, caption)
|
instapost/exceptions.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class InstagramAPIError(Exception):
|
|
2
|
+
"""Raised when Instagram API returns an error."""
|
|
3
|
+
pass
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ContainerProcessingError(InstagramAPIError):
|
|
7
|
+
"""Raised when a media container fails to process."""
|
|
8
|
+
pass
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ContainerTimeoutError(InstagramAPIError):
|
|
12
|
+
"""Raised when a media container times out during processing."""
|
|
13
|
+
pass
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Media upload utilities for converting local files to public URLs.
|
|
3
|
+
Uses Catbox for all file uploads (images and videos).
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import requests
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class MediaUploader:
|
|
12
|
+
"""Upload local media files to Catbox and return public URLs."""
|
|
13
|
+
|
|
14
|
+
CATBOX_UPLOAD_URL = "https://catbox.moe/user/api.php"
|
|
15
|
+
|
|
16
|
+
# Supported file extensions
|
|
17
|
+
SUPPORTED_IMAGES = {'.jpg', '.jpeg', '.png', '.gif', '.webp', '.bmp'}
|
|
18
|
+
SUPPORTED_VIDEOS = {'.mp4', '.mov', '.avi', '.mkv', '.flv', '.wmv', '.m4v'}
|
|
19
|
+
|
|
20
|
+
@classmethod
|
|
21
|
+
def upload(cls, file_path: str) -> str:
|
|
22
|
+
"""
|
|
23
|
+
Upload a media file (image or video) to Catbox.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
file_path: Path to local media file
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
Public URL of the uploaded file
|
|
30
|
+
|
|
31
|
+
Raises:
|
|
32
|
+
FileNotFoundError: If file doesn't exist
|
|
33
|
+
ValueError: If file type is not supported
|
|
34
|
+
requests.RequestException: If upload fails
|
|
35
|
+
"""
|
|
36
|
+
if not os.path.exists(file_path):
|
|
37
|
+
raise FileNotFoundError(f"Media file not found: {file_path}")
|
|
38
|
+
|
|
39
|
+
file_ext = Path(file_path).suffix.lower()
|
|
40
|
+
|
|
41
|
+
# Validate file type
|
|
42
|
+
if file_ext not in (cls.SUPPORTED_IMAGES | cls.SUPPORTED_VIDEOS):
|
|
43
|
+
raise ValueError(
|
|
44
|
+
f"Unsupported file type: {file_ext}. "
|
|
45
|
+
f"Supported: {cls.SUPPORTED_IMAGES | cls.SUPPORTED_VIDEOS}"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
return cls._upload_to_catbox(file_path)
|
|
49
|
+
|
|
50
|
+
@classmethod
|
|
51
|
+
def upload_image(cls, image_path: str) -> str:
|
|
52
|
+
"""
|
|
53
|
+
Upload an image to Catbox.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
image_path: Path to local image file
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
Public URL of the uploaded image
|
|
60
|
+
"""
|
|
61
|
+
if not os.path.exists(image_path):
|
|
62
|
+
raise FileNotFoundError(f"Image file not found: {image_path}")
|
|
63
|
+
|
|
64
|
+
file_ext = Path(image_path).suffix.lower()
|
|
65
|
+
if file_ext not in cls.SUPPORTED_IMAGES:
|
|
66
|
+
raise ValueError(f"Unsupported image format: {file_ext}")
|
|
67
|
+
|
|
68
|
+
return cls._upload_to_catbox(image_path)
|
|
69
|
+
|
|
70
|
+
@classmethod
|
|
71
|
+
def upload_video(cls, video_path: str) -> str:
|
|
72
|
+
"""
|
|
73
|
+
Upload a video to Catbox.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
video_path: Path to local video file
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Public URL of the uploaded video
|
|
80
|
+
"""
|
|
81
|
+
if not os.path.exists(video_path):
|
|
82
|
+
raise FileNotFoundError(f"Video file not found: {video_path}")
|
|
83
|
+
|
|
84
|
+
file_ext = Path(video_path).suffix.lower()
|
|
85
|
+
if file_ext not in cls.SUPPORTED_VIDEOS:
|
|
86
|
+
raise ValueError(f"Unsupported video format: {file_ext}")
|
|
87
|
+
|
|
88
|
+
return cls._upload_to_catbox(video_path)
|
|
89
|
+
|
|
90
|
+
@classmethod
|
|
91
|
+
def _upload_to_catbox(cls, file_path: str) -> str:
|
|
92
|
+
"""
|
|
93
|
+
Internal method to upload file to Catbox.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
file_path: Path to file
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
Public URL
|
|
100
|
+
|
|
101
|
+
Raises:
|
|
102
|
+
requests.RequestException: If upload fails
|
|
103
|
+
"""
|
|
104
|
+
with open(file_path, 'rb') as f:
|
|
105
|
+
files = {'fileToUpload': f}
|
|
106
|
+
data = {'reqtype': 'fileupload'}
|
|
107
|
+
response = requests.post(cls.CATBOX_UPLOAD_URL, data=data, files=files)
|
|
108
|
+
|
|
109
|
+
response.raise_for_status()
|
|
110
|
+
url = response.text.strip()
|
|
111
|
+
|
|
112
|
+
if not url or url.startswith('error'):
|
|
113
|
+
raise requests.RequestException(f"Catbox upload failed: {url}")
|
|
114
|
+
|
|
115
|
+
return url
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from ..api.base import BaseInstagramClient
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class CarouselPoster(BaseInstagramClient):
|
|
5
|
+
"""Post carousels (multiple images/videos) to Instagram."""
|
|
6
|
+
|
|
7
|
+
MIN_ITEMS = 2
|
|
8
|
+
MAX_ITEMS = 10
|
|
9
|
+
|
|
10
|
+
def upload(self, media_urls: list[dict], caption: str = "") -> str:
|
|
11
|
+
"""
|
|
12
|
+
Upload a carousel to Instagram.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
media_urls: List of dicts with 'media' (local file path or publicly accessible URL)
|
|
16
|
+
and 'type' ('IMAGE' or 'VIDEO') keys.
|
|
17
|
+
caption: Optional caption for the carousel.
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
Container ID for publishing.
|
|
21
|
+
"""
|
|
22
|
+
if not self.MIN_ITEMS <= len(media_urls) <= self.MAX_ITEMS:
|
|
23
|
+
raise ValueError(f"Carousel must have between {self.MIN_ITEMS} and {self.MAX_ITEMS} items")
|
|
24
|
+
|
|
25
|
+
children_ids = [self._create_child(media) for media in media_urls]
|
|
26
|
+
return self._create_container({
|
|
27
|
+
"media_type": "CAROUSEL",
|
|
28
|
+
"children": ",".join(children_ids),
|
|
29
|
+
"caption": caption,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
def post(self, media_urls: list[dict], caption: str = "") -> dict:
|
|
33
|
+
"""Upload and publish a carousel."""
|
|
34
|
+
return self.publish(self.upload(media_urls, caption))
|
|
35
|
+
|
|
36
|
+
def _create_child(self, media: dict) -> str:
|
|
37
|
+
"""Create a child container for a carousel item."""
|
|
38
|
+
media_type = media.get("type", "IMAGE").upper()
|
|
39
|
+
params = {"is_carousel_item": "true"}
|
|
40
|
+
|
|
41
|
+
if media_type == "IMAGE":
|
|
42
|
+
params["image_url"] = media["media"]
|
|
43
|
+
else:
|
|
44
|
+
params["media_type"] = "VIDEO"
|
|
45
|
+
params["video_url"] = media["media"]
|
|
46
|
+
|
|
47
|
+
container_id = self._create_container(params)
|
|
48
|
+
|
|
49
|
+
if media_type == "VIDEO":
|
|
50
|
+
self._wait_for_container(container_id)
|
|
51
|
+
|
|
52
|
+
return container_id
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from ..api.base import BaseInstagramClient
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ImagePoster(BaseInstagramClient):
|
|
5
|
+
"""Post single images to Instagram."""
|
|
6
|
+
|
|
7
|
+
def upload(self, image: str, caption: str = "") -> str:
|
|
8
|
+
"""
|
|
9
|
+
Upload a single image to Instagram.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
image: Local file path or publicly accessible URL of the image (JPEG, max 8MB).
|
|
13
|
+
caption: Optional caption for the post.
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
Container ID for publishing.
|
|
17
|
+
"""
|
|
18
|
+
return self._create_container({"image_url": image, "caption": caption})
|
|
19
|
+
|
|
20
|
+
def post(self, image: str, caption: str = "") -> dict:
|
|
21
|
+
"""Upload and publish a single image."""
|
|
22
|
+
return self.publish(self.upload(image, caption))
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from ..api.base import BaseInstagramClient
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ReelPoster(BaseInstagramClient):
|
|
7
|
+
"""Post reels to Instagram."""
|
|
8
|
+
|
|
9
|
+
def upload(
|
|
10
|
+
self,
|
|
11
|
+
video: str,
|
|
12
|
+
caption: str = "",
|
|
13
|
+
cover: Optional[str] = None,
|
|
14
|
+
share_to_feed: bool = True,
|
|
15
|
+
timeout: int = 120,
|
|
16
|
+
) -> str:
|
|
17
|
+
"""
|
|
18
|
+
Upload a reel to Instagram.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
video: Local file path or publicly accessible URL of the video (MP4, max 1GB, 3-90 seconds).
|
|
22
|
+
caption: Optional caption for the reel.
|
|
23
|
+
cover: Optional local file path or URL for custom cover image.
|
|
24
|
+
share_to_feed: Whether to also share the reel to the feed.
|
|
25
|
+
timeout: Maximum time to wait for video processing in seconds.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
Container ID for publishing.
|
|
29
|
+
"""
|
|
30
|
+
params = {
|
|
31
|
+
"media_type": "REELS",
|
|
32
|
+
"video_url": video,
|
|
33
|
+
"caption": caption,
|
|
34
|
+
"share_to_feed": str(share_to_feed).lower(),
|
|
35
|
+
}
|
|
36
|
+
if cover:
|
|
37
|
+
params["cover_url"] = cover
|
|
38
|
+
|
|
39
|
+
container_id = self._create_container(params)
|
|
40
|
+
self._wait_for_container(container_id, timeout=timeout)
|
|
41
|
+
return container_id
|
|
42
|
+
|
|
43
|
+
def post(
|
|
44
|
+
self,
|
|
45
|
+
video: str,
|
|
46
|
+
caption: str = "",
|
|
47
|
+
cover: Optional[str] = None,
|
|
48
|
+
share_to_feed: bool = True,
|
|
49
|
+
timeout: int = 120,
|
|
50
|
+
) -> dict:
|
|
51
|
+
"""Upload and publish a reel."""
|
|
52
|
+
return self.publish(self.upload(video, caption, cover, share_to_feed, timeout))
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: instapost
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python library for automating Instagram posting (images, reels, carousels)
|
|
5
|
+
Project-URL: Homepage, https://blaya.ia.br
|
|
6
|
+
Project-URL: Repository, https://github.com/pedroluz/instapost
|
|
7
|
+
Project-URL: Documentation, https://github.com/pedroluz/instapost#readme
|
|
8
|
+
Project-URL: Issues, https://github.com/pedroluz/instapost/issues
|
|
9
|
+
Author-email: Pedro Luz <blaya.luz@gmail.com>
|
|
10
|
+
Maintainer-email: Pedro Luz <blaya.luz@gmail.com>
|
|
11
|
+
License: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: automation,carousel,graph-api,instagram,meta,reels,social-media
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Environment :: Web Environment
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Natural Language :: English
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
27
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
28
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
29
|
+
Classifier: Topic :: Office/Business
|
|
30
|
+
Classifier: Typing :: Typed
|
|
31
|
+
Requires-Python: >=3.10
|
|
32
|
+
Requires-Dist: requests>=2.28.0
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# instapost
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
<img src="logo.png" width="300px" align="right" alt="logo">
|
|
42
|
+
|
|
43
|
+
A simple and powerful Python library for posting to Instagram using the Instagram Graph API.
|
|
44
|
+
|
|
45
|
+
Post images, reels, and carousels with just a few lines of code. Auto-upload local files or use remote URLs.
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
**How it works:**
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from instapost import InstagramPoster
|
|
54
|
+
|
|
55
|
+
poster = InstagramPoster(access_token="YOUR_TOKEN",
|
|
56
|
+
ig_user_id="YOUR_IG_ID"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
poster.post_image(image="./photo.jpg",
|
|
60
|
+
caption="Check this out! 📸")
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
That's it. Your photo is on Instagram.
|
|
64
|
+
|
|
65
|
+
## Setup (5 minutes)
|
|
66
|
+
|
|
67
|
+
**What you need:**
|
|
68
|
+
- Instagram Business account (connected to Facebook)
|
|
69
|
+
- Meta for Developers account (free)
|
|
70
|
+
|
|
71
|
+
**Steps:**
|
|
72
|
+
|
|
73
|
+
1. Create a Meta App → [developers.facebook.com/apps/create](https://developers.facebook.com/apps/create/)
|
|
74
|
+
2. Click **Add Product** and set up Instagram
|
|
75
|
+
3. In **App Roles > Roles**, assign **Instagram Tester** to your account
|
|
76
|
+
4. Go to **Instagram > API Setup with Instagram login**, add your account, click **Generate token**
|
|
77
|
+
5. Copy the token—you're done!
|
|
78
|
+
|
|
79
|
+
✨ **That's it.** No app review needed for personal use. Your token works immediately in Development Mode.
|
|
80
|
+
|
|
81
|
+
## Usage
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from instapost import InstagramPoster
|
|
85
|
+
|
|
86
|
+
poster = InstagramPoster(
|
|
87
|
+
access_token="YOUR_TOKEN",
|
|
88
|
+
ig_user_id="YOUR_IG_ID"
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# Post an image
|
|
92
|
+
poster.post_image(image="./photo.jpg", caption="Check this out! 📸")
|
|
93
|
+
|
|
94
|
+
# Post a reel
|
|
95
|
+
poster.post_reel(video="./video.mp4", caption="New reel! 🎬", share_to_feed=True)
|
|
96
|
+
|
|
97
|
+
# Post a carousel
|
|
98
|
+
poster.post_carousel(
|
|
99
|
+
media_urls=[
|
|
100
|
+
{"media": "./photo1.jpg", "type": "IMAGE"},
|
|
101
|
+
{"media": "./video.mp4", "type": "VIDEO"},
|
|
102
|
+
],
|
|
103
|
+
caption="Swipe through! 👉"
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
# Verify you're connected
|
|
107
|
+
print(poster.verify()['username'])
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Local files?** Just pass the file path—instapost auto-uploads to Catbox. Remote URLs work too. Mix them in one post.
|
|
111
|
+
|
|
112
|
+
## Requirements
|
|
113
|
+
|
|
114
|
+
- Instagram Business account connected to Facebook
|
|
115
|
+
- Meta for Developers account (free)
|
|
116
|
+
- Python 3.7+
|
|
117
|
+
|
|
118
|
+
## Installation
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pip install instapost
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Media Specs
|
|
125
|
+
|
|
126
|
+
| Type | Format | Size | Duration |
|
|
127
|
+
|------|--------|------|----------|
|
|
128
|
+
| Images | JPEG, PNG, WebP, GIF | ≤ 8MB | — |
|
|
129
|
+
| Reels | MP4 | ≤ 1GB | 3-90s |
|
|
130
|
+
| Carousel | 2-10 items | per item | — |
|
|
131
|
+
|
|
132
|
+
## How it works
|
|
133
|
+
|
|
134
|
+
- **Local files** → Auto-upload to Catbox → Send to Instagram API
|
|
135
|
+
- **Remote URLs** → Send directly to Instagram API
|
|
136
|
+
|
|
137
|
+
## Learn more
|
|
138
|
+
|
|
139
|
+
- [Instagram Graph API Docs](https://developers.facebook.com/docs/instagram-platform/content-publishing)
|
|
140
|
+
- [Meta for Developers](https://developers.facebook.com)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
instapost/__init__.py,sha256=HhTIume5EvcD7jWTFnJmZee3h0dpramjur8501ccWLs,539
|
|
2
|
+
instapost/client.py,sha256=Z8fZXW8PDUo2RYUb0_QaK2feJa6ZQMlm0KI0GKg5H3E,4190
|
|
3
|
+
instapost/exceptions.py,sha256=M7G5fXuLjDNoRnDSvyVqVXluHx8pxYn1VxtDX3qf3BU,347
|
|
4
|
+
instapost/api/__init__.py,sha256=6RVaMnFTtJm0l9nIC5tMBxJw7B_NFXxor7AlsqWb7hc,73
|
|
5
|
+
instapost/api/base.py,sha256=eNVUOqF_er1Kt6MMwdsk-FfO-3lUI0L-CcmPcDCy4Ko,2836
|
|
6
|
+
instapost/media/__init__.py,sha256=rhLMklySKJzeL1cCvhYfX4x-n23NAhgIzDXUT-0Aav0,65
|
|
7
|
+
instapost/media/uploader.py,sha256=cLbXUNau8EqtmnSj1xXOox4UuhHRnBo0fqlETWMcoMU,3384
|
|
8
|
+
instapost/posting/__init__.py,sha256=Jedqh7qWBfGtE9AoVPV8dWzZoNZ6xbZbejxbpmUU4lI,156
|
|
9
|
+
instapost/posting/carousel.py,sha256=XZwLfsSNiOjNzIRQOQj8k5kLQChbgUOgF0uSaZ2H32g,1782
|
|
10
|
+
instapost/posting/image.py,sha256=RH5VUyDkeiO6twRLklnLbvPkS_TJSxLG-Dl19oulHX8,721
|
|
11
|
+
instapost/posting/reel.py,sha256=-Uwbz2HoCmYzI-ZHJ97LPFMmmc4acnt0rRwgBH24RVU,1564
|
|
12
|
+
instapost-0.1.0.dist-info/METADATA,sha256=cAaCgW_vKrNz5jg1nWJkNlyB2hpOlCV3RYRMfcVBdoY,4198
|
|
13
|
+
instapost-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
14
|
+
instapost-0.1.0.dist-info/licenses/LICENSE,sha256=xnrd2Cc6EdHcx_2R8NQjcSHqSMmn3AfsT-0Jv9dI8xA,1072
|
|
15
|
+
instapost-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pedro Blaya Luz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|