Skip to main content

A fully-featured Python SDK for building Nerimity bots

Project description

nerimity-sdk

A fully-featured Python SDK for building Nerimity bots. Think discord.py, but for Nerimity.

Install

pip install nerimity-sdk

With Redis support for multi-process bots:

pip install "nerimity-sdk[redis]"

Quickstart

nerimity create my-bot
cd my-bot
# edit bot.py and set your token
python bot.py

Or manually:

from nerimity_sdk import Bot

bot = Bot(token="YOUR_TOKEN", prefix="!")

@bot.on("ready")
async def on_ready(me):
    print(f"Logged in as {me.username}#{me.tag}")

@bot.command("ping", description="Replies with Pong!")
async def ping(ctx):
    await ctx.reply("Pong!")

bot.run()

Features

Core Transport

  • Socket.IO gateway with auto-reconnect and exponential backoff
  • Event queue so gateway bursts never drop events
  • HTTP REST client with per-route rate limit buckets and retry-after handling

Event System

# Standard listener
@bot.on("message:created")
async def on_message(data): ...

# One-shot
@bot.once("ready")
async def on_first_ready(me): ...

# Wildcard — fires for every event
@bot.on("*")
async def log_all(data): ...

Every handler runs in async isolation — one crashing handler won't affect others.

Commands

@bot.command(
    "ban",
    description="Ban a user",
    usage="<user_id>",
    category="Moderation",
    guild_only=True,
    required_user_perms=[Permissions.BAN_MEMBERS],
    cooldown=5.0,
)
async def ban(ctx):
    user_id = ctx.args[0]
    await ctx.rest.ban_member(ctx.server_id, user_id)
    await ctx.reply(f"Banned {user_id}")

Flags: !cmd --silent --count=3 "quoted arg"ctx.flags["silent"], ctx.args[0]

Middleware

async def log_middleware(ctx, next):
    print(f"Command from {ctx.author.username}")
    await next(ctx)

bot.router.use(log_middleware)

Context Object

ctx.message        # Message object
ctx.author         # User
ctx.channel_id     # str
ctx.server         # Server | None (from cache)
ctx.member         # Member | None (from cache)
ctx.args           # list[str]
ctx.flags          # dict[str, Any]

await ctx.reply("hello")
await ctx.fetch_messages(limit=10)
await ctx.fetch_member(user_id)

Cache

Automatic LRU/TTL cache for servers, channels, members, users, and messages. Partial gateway updates are merged intelligently — no stale overwrites.

server = bot.cache.servers.get("server_id")
user   = bot.cache.users.get("user_id")

Permissions

from nerimity_sdk import has_permission, Permissions

if has_permission(member, server, Permissions.KICK_MEMBERS):
    ...

Plugins

from nerimity_sdk import PluginBase, listener

class ModerationPlugin(PluginBase):
    name = "moderation"

    @listener("server:member_joined")
    async def on_join(self, data):
        print("Member joined:", data)

    async def on_ready(self):
        print("Moderation plugin ready!")

async def setup(bot):
    await bot.plugins.load(ModerationPlugin())

Hot reload at runtime:

await bot.plugins.reload("moderation")

Debug Mode

bot = Bot(token="...", debug=True)
# Logs all raw gateway payloads with pretty JSON formatting

Testing

from nerimity_sdk.testing import MockBot

bot = MockBot(prefix="!")

@bot.command("ping")
async def ping(ctx):
    await ctx.reply("Pong!")

# In your test:
async def test_ping():
    await bot.simulate_message("!ping")
    bot.rest.create_message.assert_called_once()

Sharding (stub)

# Architecture is shard-ready. When Nerimity adds sharding:
bot = Bot.from_shard(token="...", shard_id=0, shard_count=4)

Project Structure

nerimity_sdk/
├── bot.py                  # Main Bot class
├── models.py               # Typed data models
├── testing.py              # MockBot + test helpers
├── transport/
│   ├── gateway.py          # Socket.IO client
│   └── rest.py             # HTTP REST client
├── events/
│   └── emitter.py          # Async event emitter
├── commands/
│   └── router.py           # Prefix command router
├── cache/
│   ├── store.py            # LRU/TTL cache
│   └── redis_adapter.py    # Optional Redis adapter
├── context/
│   └── ctx.py              # Context object
├── permissions/
│   └── checker.py          # Permission helpers
├── plugins/
│   └── manager.py          # Plugin system
├── cli/
│   └── main.py             # nerimity CLI
└── utils/
    └── logging.py          # Structured logging

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nerimity_sdk-0.1.0.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nerimity_sdk-0.1.0-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file nerimity_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: nerimity_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for nerimity_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 933593ca191fc86a4dbb666112f8cc888a0c37dd38e42a8563df9d654447b6e6
MD5 a31a4f8838a7ef937d22d9ca8028669f
BLAKE2b-256 9995c9b9b4e38020780e0d419c72c19c5a21888f31f8a37ac8d7f1fb8719c70d

See more details on using hashes here.

File details

Details for the file nerimity_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nerimity_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 34.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for nerimity_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e61e3742c7b2be930f56b658e3f8bcf04506282207d6b88ee291be9618b3641e
MD5 e996b7d9bbd04bf10433b46673757fe7
BLAKE2b-256 f4a8f33f066067cd99adb713fa090ea7522d22d242b9ec178d374d3be1300c53

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page