instapost 0.1.0__tar.gz

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.
@@ -0,0 +1,138 @@
1
+ *.ipynb
2
+ # Byte-compiled / optimized / DLL files
3
+ __pycache__/
4
+ *.py[cod]
5
+ *$py.class
6
+
7
+ # C extensions
8
+ *.so
9
+
10
+ # Distribution / packaging
11
+ .Python
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ wheels/
24
+ pip-wheel-metadata/
25
+ share/python-wheels/
26
+ *.egg-info/
27
+ .installed.cfg
28
+ *.egg
29
+ MANIFEST
30
+
31
+ # PyInstaller
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+
53
+ # Translations
54
+ *.mo
55
+ *.pot
56
+
57
+ # Django stuff:
58
+ *.log
59
+ local_settings.py
60
+ db.sqlite3
61
+ db.sqlite3-journal
62
+
63
+ # Flask stuff:
64
+ instance/
65
+ .webassets-cache
66
+
67
+ # Scrapy stuff:
68
+ .scrapy
69
+
70
+ # Sphinx documentation
71
+ docs/_build/
72
+
73
+ # PyBuilder
74
+ target/
75
+
76
+ # Jupyter Notebook
77
+ .ipynb_checkpoints
78
+ *.ipynb
79
+
80
+ # IPython
81
+ profile_default/
82
+ ipython_config.py
83
+
84
+ # pyenv
85
+ .python-version
86
+
87
+ # pipenv
88
+ Pipfile.lock
89
+
90
+ # PEP 582
91
+ __pypackages__/
92
+
93
+ # Celery stuff
94
+ celerybeat-schedule
95
+ celerybeat.pid
96
+
97
+ # SageMath parsed files
98
+ *.sage.py
99
+
100
+ # Environments
101
+ .env
102
+ .venv
103
+ env/
104
+ venv/
105
+ ENV/
106
+ env.bak/
107
+ venv.bak/
108
+
109
+ # Spyder project settings
110
+ .spyderproject
111
+ .spyproject
112
+
113
+ # Rope project settings
114
+ .ropeproject
115
+
116
+ # mkdocs documentation
117
+ /site
118
+
119
+ # mypy
120
+ .mypy_cache/
121
+ .dmypy.json
122
+ dmypy.json
123
+
124
+ # Pyre type checker
125
+ .pyre/
126
+
127
+ # IDE
128
+ .vscode/
129
+ .idea/
130
+ *.swp
131
+ *.swo
132
+ *~
133
+ .DS_Store
134
+
135
+ # Project specific
136
+ *.pem
137
+ *.key
138
+ .flake8
@@ -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.
@@ -0,0 +1,6 @@
1
+ include README.md
2
+ include LICENSE
3
+ include requirements.txt
4
+ recursive-exclude * __pycache__
5
+ recursive-exclude * *.py[cod]
6
+ recursive-exclude tests *
@@ -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,103 @@
1
+ # instapost
2
+
3
+
4
+ <img src="logo.png" width="300px" align="right" alt="logo">
5
+
6
+ A simple and powerful Python library for posting to Instagram using the Instagram Graph API.
7
+
8
+ Post images, reels, and carousels with just a few lines of code. Auto-upload local files or use remote URLs.
9
+
10
+
11
+
12
+
13
+ **How it works:**
14
+
15
+ ```python
16
+ from instapost import InstagramPoster
17
+
18
+ poster = InstagramPoster(access_token="YOUR_TOKEN",
19
+ ig_user_id="YOUR_IG_ID"
20
+ )
21
+
22
+ poster.post_image(image="./photo.jpg",
23
+ caption="Check this out! 📸")
24
+ ```
25
+
26
+ That's it. Your photo is on Instagram.
27
+
28
+ ## Setup (5 minutes)
29
+
30
+ **What you need:**
31
+ - Instagram Business account (connected to Facebook)
32
+ - Meta for Developers account (free)
33
+
34
+ **Steps:**
35
+
36
+ 1. Create a Meta App → [developers.facebook.com/apps/create](https://developers.facebook.com/apps/create/)
37
+ 2. Click **Add Product** and set up Instagram
38
+ 3. In **App Roles > Roles**, assign **Instagram Tester** to your account
39
+ 4. Go to **Instagram > API Setup with Instagram login**, add your account, click **Generate token**
40
+ 5. Copy the token—you're done!
41
+
42
+ ✨ **That's it.** No app review needed for personal use. Your token works immediately in Development Mode.
43
+
44
+ ## Usage
45
+
46
+ ```python
47
+ from instapost import InstagramPoster
48
+
49
+ poster = InstagramPoster(
50
+ access_token="YOUR_TOKEN",
51
+ ig_user_id="YOUR_IG_ID"
52
+ )
53
+
54
+ # Post an image
55
+ poster.post_image(image="./photo.jpg", caption="Check this out! 📸")
56
+
57
+ # Post a reel
58
+ poster.post_reel(video="./video.mp4", caption="New reel! 🎬", share_to_feed=True)
59
+
60
+ # Post a carousel
61
+ poster.post_carousel(
62
+ media_urls=[
63
+ {"media": "./photo1.jpg", "type": "IMAGE"},
64
+ {"media": "./video.mp4", "type": "VIDEO"},
65
+ ],
66
+ caption="Swipe through! 👉"
67
+ )
68
+
69
+ # Verify you're connected
70
+ print(poster.verify()['username'])
71
+ ```
72
+
73
+ **Local files?** Just pass the file path—instapost auto-uploads to Catbox. Remote URLs work too. Mix them in one post.
74
+
75
+ ## Requirements
76
+
77
+ - Instagram Business account connected to Facebook
78
+ - Meta for Developers account (free)
79
+ - Python 3.7+
80
+
81
+ ## Installation
82
+
83
+ ```bash
84
+ pip install instapost
85
+ ```
86
+
87
+ ## Media Specs
88
+
89
+ | Type | Format | Size | Duration |
90
+ |------|--------|------|----------|
91
+ | Images | JPEG, PNG, WebP, GIF | ≤ 8MB | — |
92
+ | Reels | MP4 | ≤ 1GB | 3-90s |
93
+ | Carousel | 2-10 items | per item | — |
94
+
95
+ ## How it works
96
+
97
+ - **Local files** → Auto-upload to Catbox → Send to Instagram API
98
+ - **Remote URLs** → Send directly to Instagram API
99
+
100
+ ## Learn more
101
+
102
+ - [Instagram Graph API Docs](https://developers.facebook.com/docs/instagram-platform/content-publishing)
103
+ - [Meta for Developers](https://developers.facebook.com)
@@ -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"
@@ -0,0 +1,3 @@
1
+ from .base import BaseInstagramClient
2
+
3
+ __all__ = ["BaseInstagramClient"]
@@ -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)
@@ -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)
@@ -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,3 @@
1
+ from .uploader import MediaUploader
2
+
3
+ __all__ = ["MediaUploader"]