Skip to content

aaronstevenson408/torn-api-python

Repository files navigation

TornAPI Wrapper

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.

Table of Contents

Features

  • 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.

Installation

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.txt

Configuration

Create 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=

Usage

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 class

You 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)

Example Usage

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()

API Reference

For detailed information on the available methods and classes, refer to the Unofficial Torn API documentation.

Contributing

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.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages