Skip to main content

Nginr - Python Alt syntax with fn keyword and .xr files

Project description

nginr

Nginr is a Python syntax alternative (or dialect) that allows using the fn keyword instead of def. It is not a new programming language, but rather a preprocessor that converts .xr files into standard Python code before execution.

Inspired by Python’s readability, Nginr adds a fun twist by using fn — making your code feel fresh-modern while staying fully compatible with Python.


Features

  • Full Python Compatibility: Use any Python3 library or framework
  • Alternative Syntax: fn keyword instead of def | but still can use def
  • Seamless Integration: Works with existing Python tooling
  • Lightweight: Simple preprocessing with minimal overhead
  • Extensible: Supports all Python 3.7+ syntax and libraries

Installation

Using pip (recommended)

pip install nginr

From source

git clone https://github.com/nginrsw/nginr.git
cd nginr
pip install -e .

Quick Start

  1. Create a file with .xr extension:
# hello.xr
fn hello(name):
    print(f"Hello, {name}!")

hello("World")
  1. Run it with:
nginr hello.xr

How It Works

Nginr is a simple preprocessor:

  1. Reads .xr files
  2. Replaces fn with def
  3. Executes the resulting Python code

Example Conversion

# Input (hello.xr)
fn greet(name):
    print(f"Hi, {name}!")

# After preprocessing:
def greet(name):
    print(f"Hi, {name}!")

More Examples

Function with Parameters

fn add(a, b):
    return a + b

result = add(5, 3)
print(f"5 + 3 = {result}")

Loops and Conditionals

fn factorial(n):
    if n <= 1:
        return 1
    return n * factorial(n - 1)

for i in range(1, 6):
    print(f"{i}! = {factorial(i)}")

Using External Libraries

fn calculate_stats(data):
    import numpy as np
    import pandas as pd

    df = pd.DataFrame(data)
    return {
        'mean': np.mean(df.values),
        'std': np.std(df.values),
        'sum': np.sum(df.values)
    }

Using the Standard Library

fn get_weather(city):
    import json
    from urllib.request import urlopen

    with urlopen(f'https://weather.example.com/api?city={city}') as response:
        return json.load(response)

Python Library Compatibility

You can use any Python package in your .xr files.

Install them as usual:

pip install numpy pandas requests

CLI Options

Run this to see available options:

nginr --help

You can also pass arguments to your .xr script:

nginr script.xr arg1 arg2

Limitations

  • Only performs basic fn → def substitution
  • No new syntax or typing system
  • .xr errors will show traceback in the transformed .py version
  • No built-in macro system or advanced parsing (yet)

Contributing

Contributions are welcome!

  1. Fork the repo
  2. Create a feature branch git checkout -b feature/amazing-feature
  3. Commit your changes git commit -m 'Add amazing feature'
  4. Push your branch git push origin feature/amazing-feature
  5. Open a Pull Request

License

Licensed under the MIT License.

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

nginr-0.1.7.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

nginr-0.1.7-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file nginr-0.1.7.tar.gz.

File metadata

  • Download URL: nginr-0.1.7.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for nginr-0.1.7.tar.gz
Algorithm Hash digest
SHA256 e6fb7aaa75d8679ba447b7fd1e0ac2ddfd32264edc526b9496a7b54b22acee18
MD5 55f7b53acc48d5921932d89f27a2af45
BLAKE2b-256 ef54b3e38dd2a237a24b6a0b6b6f8ceda351b85186cb65cca671227b8cefcb59

See more details on using hashes here.

File details

Details for the file nginr-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: nginr-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for nginr-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 4b2d57658b62ab52094bad0e06576578093df8528306c5f20c2fafb25f1124f0
MD5 021a08a5d902ffc6a0afc4f8c3218771
BLAKE2b-256 828e1853074c0dd880787591ef1bd6397c312b92a484a892fb11e934efbea854

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