A Python wrapper for the Torn API, designed to simplify interactions with the Torn RPG game. This project provides an easy-to-use interface for accessing various features of the Torn API.
- Fetch user data and selections.
- Rate limiting to manage API calls efficiently.
- Support for multiple sections (e.g., User,Property, etc)
- Built-in logging for debugging and tracking.
To install the TornAPI wrapper, clone the repository and install the required dependencies:
git clone https://github.com/aaronstevenson408/tornapi-wrapper.git
cd tornapi-wrapper
pip install -r requirements.txtCreate a .env file in the root directory of your project and add the following variables:
# .env
# Debug Level
DEBUG_LEVEL=Critical # Change this to INFO, WARNING, ERROR, or CRITICAL as needed
# Test Variables
Test-Full=
Test-Limited=
Test-Min=
Test-Public=
To use the TornAPI wrapper, initialize the API and use the Sections class to access various user-related features. Here’s a simple example:
from tornApi import TornAPI
from sections import Sections
api = TornAPI() # Initializes the TornAPI instance
sections = Sections(api) # Initializes the Sections classYou can then interact with the API to fetch user data as follows:
user = sections.user('') # Replace with a valid user ID
user_properties = user.properties.fetch_properties()
print(user_properties.properties[0].property_data)Here’s a concise example demonstrating various API calls:
from tornApi import TornAPI
from sections import Sections
api = TornAPI()
sections = Sections(api)
user = sections.user('') # Replace with a valid user ID
torn = sections.torn(id = "101")
# Fetching user properties and displaying data
user_properties = user.properties.fetch_properties()
property = sections.property(user_properties.properties[0].id)
# Fetching various user data
print(user.basic.fetch_data())
print(user.ammo.fetch_data())
print(user.skills.fetch_data())
print(property.property.fetch_data())
# alternatively you can fetch all data for a section like this:
cityshops_example = torn.CityShops(api)
cityshops_example.fetch_data()
print(cityshops_example.data.shops)
api.close()For detailed information on the available methods and classes, refer to the Unofficial Torn API documentation.
Contributions are welcome! If you'd like to contribute, please fork the repository and create a pull request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.