
# PyFiveSim
> Sync/async Python wrapper for [5sim](https://5sim.biz/) API
## Installing
pip install PyFiveSim
## Features
* Two available clients: sync (HTTPX) and async (AIOHTTP), which can be used as context managers or as instances
* Methods return Pydantic model as result for easier interaction with data
* Enums for prettier code
* Full exception handling
> Library documentation is already in development...
## Usage
```python
import asyncio
from pyfivesim import PyFiveSimAsync
from pyfivesim.exceptions import (
FiveSimNotEnoughBalance,
FiveSimUnknownError,
FiveSimNoFreePhones,
)
from pyfivesim.enums import (
OrderAction,
Status,
)
async def main():
api_key = "YOUR_API_KEY"
# Create a client instance or use async with ...
client = PyFiveSimAsync(
api_key=api_key,
base_url="https://5sim.net/v1" # Optional, default is "https://5sim.biz/v1",
)
# or use sync client PyFiveSimSync(api_key=api_key)
# Get the user profile and print the ID, balance, and rating
profile = await client.get_user_profile()
print("ID >>>", profile.id)
print("Balance >>>", profile.balance)
print("Rating >>>", profile.rating)
# Get last 5 user orders and print the service and price
for order in profile.last_top_orders:
print("Service >>>", order.service)
print("Operator >>>", order.operator)
print("Price >>>", order.price)
# Try to buy a number
try:
order = await client.buy_number(
product="youdo",
country="russia",
max_price=5,
)
except FiveSimNotEnoughBalance:
print("O-o-p-s! Not enough balance :(")
except FiveSimNoFreePhones:
print("O-o-p-s! No free numbers :(")
except FiveSimUnknownError as exc:
print("Unknown error occurred :(")
print("Error status code >>>", exc.status_code)
print("Error message >>>", exc.data)
else:
print("W-o-o-h-o-o! Number bought successfully!")
print("Phone number >>>", order.phone)
print("Price >>>", order.price)
print("Start checking for SMS...")
sleep_for = 5
while not order.status == Status.FINISHED:
await asyncio.sleep(sleep_for)
order = await client.get_order_info(order.id)
if order.sms:
print("SMS received! :)")
print("SMS text >>>", order.sms.text)
print("SMS code >>>", order.sms.code)
print("Finish the order...")
await client.action_with_order(OrderAction.FINISH, order.id)
print("Order finished successfully!")
break
else:
print(f"No SMS received yet, sleep for {sleep_for} seconds :(")
if __name__ == "__main__":
asyncio.run(main())
```
## Docs
> Go to https://5sim.biz/ for more information about API methods
Raw data
{
"_id": null,
"home_page": "https://github.com/Belyashik2K/PyFiveSim",
"name": "PyFiveSim",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Belyashik2K",
"author_email": "work@belyashik2k.ru",
"download_url": "https://files.pythonhosted.org/packages/b8/2d/425c27e7367254fd90cd3879ec19bd77a030a78b5a269c48b68ed7a93fd3/PyFiveSim-1.0.2.tar.gz",
"platform": null,
"description": "\r\n\r\n# PyFiveSim\r\n> Sync/async Python wrapper for [5sim](https://5sim.biz/) API\r\n\r\n## Installing\r\n\r\n pip install PyFiveSim\r\n\r\n## Features\r\n* Two available clients: sync (HTTPX) and async (AIOHTTP), which can be used as context managers or as instances\r\n* Methods return Pydantic model as result for easier interaction with data\r\n* Enums for prettier code\r\n* Full exception handling\r\n> Library documentation is already in development...\r\n\r\n## Usage\r\n```python\r\nimport asyncio\r\n\r\nfrom pyfivesim import PyFiveSimAsync\r\nfrom pyfivesim.exceptions import (\r\n FiveSimNotEnoughBalance,\r\n FiveSimUnknownError,\r\n FiveSimNoFreePhones,\r\n)\r\nfrom pyfivesim.enums import (\r\n OrderAction,\r\n Status,\r\n)\r\n\r\n\r\nasync def main():\r\n api_key = \"YOUR_API_KEY\"\r\n \r\n # Create a client instance or use async with ...\r\n client = PyFiveSimAsync(\r\n api_key=api_key,\r\n base_url=\"https://5sim.net/v1\" # Optional, default is \"https://5sim.biz/v1\",\r\n )\r\n # or use sync client PyFiveSimSync(api_key=api_key)\r\n \r\n # Get the user profile and print the ID, balance, and rating\r\n profile = await client.get_user_profile()\r\n print(\"ID >>>\", profile.id)\r\n print(\"Balance >>>\", profile.balance)\r\n print(\"Rating >>>\", profile.rating)\r\n # Get last 5 user orders and print the service and price\r\n for order in profile.last_top_orders:\r\n print(\"Service >>>\", order.service)\r\n print(\"Operator >>>\", order.operator)\r\n print(\"Price >>>\", order.price)\r\n\r\n # Try to buy a number\r\n try:\r\n order = await client.buy_number(\r\n product=\"youdo\",\r\n country=\"russia\",\r\n max_price=5,\r\n )\r\n except FiveSimNotEnoughBalance:\r\n print(\"O-o-p-s! Not enough balance :(\")\r\n except FiveSimNoFreePhones:\r\n print(\"O-o-p-s! No free numbers :(\")\r\n except FiveSimUnknownError as exc:\r\n print(\"Unknown error occurred :(\")\r\n print(\"Error status code >>>\", exc.status_code)\r\n print(\"Error message >>>\", exc.data)\r\n else:\r\n print(\"W-o-o-h-o-o! Number bought successfully!\")\r\n print(\"Phone number >>>\", order.phone)\r\n print(\"Price >>>\", order.price)\r\n\r\n print(\"Start checking for SMS...\")\r\n sleep_for = 5\r\n while not order.status == Status.FINISHED:\r\n await asyncio.sleep(sleep_for)\r\n order = await client.get_order_info(order.id)\r\n if order.sms:\r\n print(\"SMS received! :)\")\r\n print(\"SMS text >>>\", order.sms.text)\r\n print(\"SMS code >>>\", order.sms.code)\r\n print(\"Finish the order...\")\r\n await client.action_with_order(OrderAction.FINISH, order.id)\r\n print(\"Order finished successfully!\")\r\n break\r\n else:\r\n print(f\"No SMS received yet, sleep for {sleep_for} seconds :(\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n asyncio.run(main())\r\n```\r\n\r\n## Docs\r\n> Go to https://5sim.biz/ for more information about API methods\r\n\r\n",
"bugtrack_url": null,
"license": "MIT license",
"summary": "Sync/async Python wrapper for 5sim API",
"version": "1.0.2",
"project_urls": {
"Homepage": "https://github.com/Belyashik2K/PyFiveSim"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b82d425c27e7367254fd90cd3879ec19bd77a030a78b5a269c48b68ed7a93fd3",
"md5": "c00bf6fd33566e326e816c45d1409d70",
"sha256": "b6a63e82bb8f85398f41d1086cf1f94894e0e4df305898c7c98c04d0d25f5c40"
},
"downloads": -1,
"filename": "PyFiveSim-1.0.2.tar.gz",
"has_sig": false,
"md5_digest": "c00bf6fd33566e326e816c45d1409d70",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 15456,
"upload_time": "2024-09-01T17:20:52",
"upload_time_iso_8601": "2024-09-01T17:20:52.139593Z",
"url": "https://files.pythonhosted.org/packages/b8/2d/425c27e7367254fd90cd3879ec19bd77a030a78b5a269c48b68ed7a93fd3/PyFiveSim-1.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-01 17:20:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Belyashik2K",
"github_project": "PyFiveSim",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pyfivesim"
}