Metadata-Version: 2.4
Name: infraforge
Version: 0.1.0
Summary: Official Python SDK for InfraForge — self-hosted project provisioning platform
Author: InfraForge
License: MIT
Project-URL: Homepage, https://infraforge.digitalforge.ia.br
Project-URL: Source, https://github.com/your-org/infraforge
Keywords: infraforge,baas,postgres,auth,rls
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.28

# InfraForge — Python SDK

Official Python client for the [InfraForge](https://infraforge.digitalforge.ia.br) platform.

## Install

```bash
pip install infraforge
```

## Quickstart

```python
from infraforge import Client

client = Client(
    url="https://infraforge.example.com",
    project_slug="my-app",
    api_key="if_xxxxx",  # from the project settings
)

# Register a user (may return pending=True if admin approval is required)
result = client.sign_up(email="alice@example.com", password="secret123")
print(result)

# Login
session = client.sign_in(email="alice@example.com", password="secret123")
print(session.user.email, session.token)

# Run a SQL query — RLS is enforced automatically using the JWT
rows = client.query(
    "SELECT id, title FROM posts WHERE author_id = current_user_id()"
)
for r in rows:
    print(r["title"])

# Parameterized
rows = client.query(
    "SELECT * FROM posts WHERE id = $1",
    [42],
)

# Logout (clears in-memory session)
client.sign_out()
```

## Social login (browser flow)

The InfraForge OAuth flow happens in the browser. Use `social_login_url` to build
the URL the user must visit; after auth, they're redirected to your app with the
JWT in the URL fragment (`#token=...`). Your frontend extracts it and posts it back
to your Python service, which loads it via `set_token`.

```python
url = client.social_login_url(provider="google", redirect_to="https://app.example.com/callback")
# Redirect user to `url`; back in /callback, parse #token=... from JS,
# POST it to your backend, then:
client.set_token(token)
```

## Password reset

```python
client.request_password_reset("alice@example.com")
# Always succeeds (silent if email doesn't exist — anti-enumeration)
```

## Error handling

All failures raise either `AuthError` or `QueryError`:

```python
from infraforge import Client, AuthError

try:
    client.sign_in("a@b.com", "wrong")
except AuthError as e:
    if e.pending:
        print("Account waiting admin approval")
    else:
        print(f"Login failed: {e}")
```

## License

MIT
