Python bindings for Instagram Private API
Project description
igapi-rs
Instagram 私有 API 的 Python 绑定,基于 Rust + PyO3 构建,高性能、异步优先。
支持 Android / iOS / Web 三平台模拟。
安装
pip install igapi-rs
环境要求
- Python 3.10+
快速开始
import igapi
# 创建客户端
client = igapi.Client()
# 登录
client.login("username", "password")
# 获取用户信息
user = client.user_info(12345678)
print(f"用户: @{user.username}")
print(f"粉丝数: {user.follower_count}")
# 搜索用户
results = client.search_users("instagram")
for user in results:
print(f"@{user.username}")
# 获取用户动态
feed = client.user_feed(12345678)
for media in feed.items:
print(f"媒体: {media.id}, 点赞: {media.like_count}")
API 参考
Client
Client(proxy: str | None = None, platform: str = "android")
创建新的 Instagram API 客户端。
参数:
proxy(可选): 代理 URL(例如 "http://localhost:8080")platform(可选): 使用的平台("android" 或 "web")
方法:
login(username: str, password: str) -> None
登录 Instagram。
异常:
PermissionError: 登录失败(密码错误、需要验证等)ValueError: 无效的凭据RuntimeError: 网络或 API 错误
is_logged_in() -> bool
检查当前是否已登录。
user_info(user_id: int) -> User
通过 ID 获取用户信息。
异常:
KeyError: 用户未找到PermissionError: 需要登录
search_users(query: str) -> list[User]
通过用户名或名称搜索用户。
user_feed(user_id: int, max_id: str | None = None) -> Feed
获取用户的媒体动态。
参数:
user_id: 要获取动态的用户 IDmax_id(可选): 分页游标
类型定义
User
class User:
pk: int # 用户 ID
username: str # 用户名
full_name: str # 全名
is_private: bool # 是否私密账户
profile_pic_url: str # 头像 URL
follower_count: int # 粉丝数
following_count: int # 关注数
Media
class Media:
id: str # 媒体 ID
media_type: int # 类型(1=图片, 2=视频, 8=轮播)
caption_text: str # 描述文字
like_count: int # 点赞数
comment_count: int # 评论数
Feed
class Feed:
items: list[Media] # 媒体项目列表
has_more: bool # 是否有更多项目
next_cursor: str | None # 下一页游标
错误处理
try:
client.login("user", "pass")
except PermissionError as e:
# 登录失败、需要验证、双因素认证等
print(f"登录错误: {e}")
except ValueError as e:
# 无效的凭据
print(f"无效输入: {e}")
except RuntimeError as e:
# API 或网络错误
print(f"错误: {e}")
使用代理
# HTTP 代理
client = igapi.Client(proxy="http://localhost:8080")
# HTTPS 代理
client = igapi.Client(proxy="https://proxy.example.com:8080")
# SOCKS 代理
client = igapi.Client(proxy="socks5://localhost:1080")
示例
完整使用示例请参见 examples/python_example.py。
开发
构建
# 调试构建
maturin develop
# 发布构建
maturin develop --release
# 构建 wheel 包
maturin build --release
测试
# 运行测试
python -m pytest tests/
# 类型检查
mypy --strict examples/
性能
Python 绑定使用 PyO3,保持接近原生 Rust 的性能:
- API 调用通过 Tokio 异步处理
- 最小化序列化开销
- 尽可能使用零拷贝数据访问
许可证
MIT OR Apache-2.0
链接
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file igapi_rs-0.0.6.dev0-cp312-cp312-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: igapi_rs-0.0.6.dev0-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87a2619bb187afe06dcd71a00c1813b4b345a59d8f787c8105ffe160f1530423
|
|
| MD5 |
471af1b78802ba96ae388c2ef01513c4
|
|
| BLAKE2b-256 |
13ea48bfd6a589161d3315a82c763a2936ddab083104c0ed46472f7e8394e808
|
Provenance
The following attestation bundles were made for igapi_rs-0.0.6.dev0-cp312-cp312-manylinux_2_28_x86_64.whl:
Publisher:
build-and-release.yml on open-luban/igapi-rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
igapi_rs-0.0.6.dev0-cp312-cp312-manylinux_2_28_x86_64.whl -
Subject digest:
87a2619bb187afe06dcd71a00c1813b4b345a59d8f787c8105ffe160f1530423 - Sigstore transparency entry: 1131038888
- Sigstore integration time:
-
Permalink:
open-luban/igapi-rs@573726c301c63d94492037d130b0cbe964d6ae2a -
Branch / Tag:
refs/tags/test-v0.0.6 - Owner: https://github.com/open-luban
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-release.yml@573726c301c63d94492037d130b0cbe964d6ae2a -
Trigger Event:
push
-
Statement type:
File details
Details for the file igapi_rs-0.0.6.dev0-cp312-cp312-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: igapi_rs-0.0.6.dev0-cp312-cp312-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 3.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40c2294c8fa62ab5f0ef93860ea1a40e4bf913b3c3df6c37b4577829f27dbdf9
|
|
| MD5 |
c3e0f9f8e7277249cb5e529eb3cb4b77
|
|
| BLAKE2b-256 |
4e3f27eab25d1209b4e9075a44dc4e2dbad14cf3f3877f6d6abf89adf00dea77
|
Provenance
The following attestation bundles were made for igapi_rs-0.0.6.dev0-cp312-cp312-manylinux_2_28_aarch64.whl:
Publisher:
build-and-release.yml on open-luban/igapi-rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
igapi_rs-0.0.6.dev0-cp312-cp312-manylinux_2_28_aarch64.whl -
Subject digest:
40c2294c8fa62ab5f0ef93860ea1a40e4bf913b3c3df6c37b4577829f27dbdf9 - Sigstore transparency entry: 1131038925
- Sigstore integration time:
-
Permalink:
open-luban/igapi-rs@573726c301c63d94492037d130b0cbe964d6ae2a -
Branch / Tag:
refs/tags/test-v0.0.6 - Owner: https://github.com/open-luban
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-release.yml@573726c301c63d94492037d130b0cbe964d6ae2a -
Trigger Event:
push
-
Statement type:
File details
Details for the file igapi_rs-0.0.6.dev0-cp312-cp312-macosx_10_13_x86_64.macosx_11_0_arm64.macosx_10_13_universal2.whl.
File metadata
- Download URL: igapi_rs-0.0.6.dev0-cp312-cp312-macosx_10_13_x86_64.macosx_11_0_arm64.macosx_10_13_universal2.whl
- Upload date:
- Size: 6.1 MB
- Tags: CPython 3.12, macOS 10.13+ universal2 (ARM64, x86-64), macOS 10.13+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a0f8eeb6a195fd8083f947ebcbf255094a92b4df3e895980c6c3733adaa62b7
|
|
| MD5 |
c0e8f06329d6a6dde0bdecc15efa8dcd
|
|
| BLAKE2b-256 |
fe47f63b21cc70ca73b68fe10b6aaaa351bab76e12dd277b85d06f64d5e9b890
|
Provenance
The following attestation bundles were made for igapi_rs-0.0.6.dev0-cp312-cp312-macosx_10_13_x86_64.macosx_11_0_arm64.macosx_10_13_universal2.whl:
Publisher:
build-and-release.yml on open-luban/igapi-rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
igapi_rs-0.0.6.dev0-cp312-cp312-macosx_10_13_x86_64.macosx_11_0_arm64.macosx_10_13_universal2.whl -
Subject digest:
3a0f8eeb6a195fd8083f947ebcbf255094a92b4df3e895980c6c3733adaa62b7 - Sigstore transparency entry: 1131038847
- Sigstore integration time:
-
Permalink:
open-luban/igapi-rs@573726c301c63d94492037d130b0cbe964d6ae2a -
Branch / Tag:
refs/tags/test-v0.0.6 - Owner: https://github.com/open-luban
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-release.yml@573726c301c63d94492037d130b0cbe964d6ae2a -
Trigger Event:
push
-
Statement type: