Skip to main content

Nginr - Python Alt syntax with fn keyword and .xg 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 .xg 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 .xg extension:
# hello.xg
fn hello(name):
    print(f"Hello, {name}!")

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

How It Works

Nginr is a simple preprocessor:

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

Example Conversion

# Input (hello.xg)
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 .xg 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 .xg script:

nginr script.xg arg1 arg2

Limitations

  • Only performs basic fn → def substitution
  • No new syntax or typing system
  • .xg 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.6.tar.gz (4.5 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.6-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nginr-0.1.6.tar.gz
  • Upload date:
  • Size: 4.5 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.6.tar.gz
Algorithm Hash digest
SHA256 81b6301d929590269ec82a5a527367c55be2e3ffe520ebf66ea9ff65133c9823
MD5 841293072a22b879a9eb511227c41f21
BLAKE2b-256 dd1d74158401e4a4413745c8cd1191e249df17d964bb33ca117c2b5af2274561

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nginr-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 4.5 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e5862a761fd6173be9db585bb065c9c503ef20b8d8c273b537387e4963ac9509
MD5 0a0044c4c3597939385cb4cdfe1322db
BLAKE2b-256 d3202f9380593d6a19423e6cbfd3828c7e25305fbd28b5cbadc6cade2c69ee20

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